You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importNGNfrom'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 namespaceconstcrypto=NGN.plugins.crypto// Key Generationconst{ publicKey, privateKey }=awaitcrypto.generateKeys()// Content signing/verificationconstcontent='my data'constsignature=awaitcrypto.sign(content,privateKey)constverified=awaitcrypto.verify(content,signature,publicKey)// Shared key encryptionconstsharedKey='my secret'constencrypted=awaitcrypto.encrypt(content,sharedKey)constdecrypted=awaitcrypto.decrypt(encrypted,sharedKey)// Public key encryption/Private key decryptionconstencrypted=awaitcrypto.encrypt(content,publicKey)constdecrypted=awaitcrypto.encrypt(content,privateKey)