Skip to content
/ crypto Public

A cryptography plugin for the NGN JavaScript ecosystem

License

Notifications You must be signed in to change notification settings

ngnjs/crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NGN Crypto

The NGN Cryptography plugin implements libcrypto, making it accessible from NGN and for all other NGN plugins. The following libcrypto methods are available:

  • generateKeys()
  • sign()
  • verify()
  • encrypt()
  • decrypt()
  • encryptionAlgorithm()
  • JWT.createToken()
  • JWT.verifyToken()
  • base32

Notice: libcrypto contains additional features which aren't commonly used. This plugin exposes the minimum number of functions required to cover the most common cryptography needs in the smallest package possible. The other functions can be imported directly from libcrypto into projects that need them.

The fundamental/basic example:

import NGN from 'https://cdn.jsdelivr.net/npm/ngn@latest/index.js'
import 'https://cdn.jsdelivr.net/npm/@ngnjs/crypto/index.js'
// Alternative import:
// import crypto from 'https://cdn.jsdelivr.net/npm/@ngnjs/crypto/index.js'

// The crypto library is accessible from the NGN namespace
const crypto = NGN.plugins.crypto

// Key Generation
const { publicKey, privateKey } = await crypto.generateKeys()

// Content signing/verification
const content = 'my data'
const signature = await crypto.sign(content, privateKey)
const verified = await crypto.verify(content, signature, publicKey)

// Shared key encryption
const sharedKey = 'my secret'
const encrypted = await crypto.encrypt(content, sharedKey)
const decrypted = await crypto.decrypt(encrypted, sharedKey)

// Public key encryption/Private key decryption
const encrypted = await crypto.encrypt(content, publicKey)
const decrypted = await crypto.encrypt(content, privateKey)

For more specific examples and documentation, see the libcrypto repository.

About

A cryptography plugin for the NGN JavaScript ecosystem

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published