Tiny module for easy encryption of Buffers
const secretBlob = require('secret-blob')
const key = secretBlob.keygen()
const message = Buffer.from('Hello world')
const encrypted = secretBlob.encrypt(message, key)
const decrypted = secretBlob.decrypt(encrypted, key)
console.log(decrypted.toString()) // Hello world
Generate a new key. Optionally pass Buffer
key
to write to.
Must be secretBlob.KEYBYTES
long.
Returns a sodium-native
secret Buffer
.
Encrypt plaintext
under key
. Optionally pass Buffer
ciphertext
to write
to. Must be secretBlob.encryptLength(plaintext)
long.
Returns a normal Buffer
.
Returns the number of bytes required to encrypt plaintext
.
Simply plaintext.byteLength + secretBlob.HEADERBYTES
.
Decrypt ciphertext
under key
. Optionally pass Buffer
plaintext
to write
to. Must be secretBlob.decryptLength(plaintext)
long.
Returns a sodium-native
secret Buffer
.
Returns the number of bytes required to encrypt ciphertext
.
Simply ciphertext.byteLength - secretBlob.HEADERBYTES
.
KEYBYTES
: Byte length of a keyHEADERBYTES
: Byte length of the header added to ciphertext
npm install secret-blob