@ngnjs/crypto
v1.0.0-alpha.11
Published
A cryptography plugin for NGN
Downloads
5
Keywords
Readme
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()
encryptJSON()
decryptJSON()
encryptionAlgorithm()
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.