1.1.0 • Published 4 years ago

secret-blob v1.1.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

secret-blob

Build Status

Tiny module for easy encryption of Buffers

Usage

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

API

const key = secretBlob.keygen([key])

Generate a new key. Optionally pass Buffer key to write to. Must be secretBlob.KEYBYTES long.

Returns a sodium-native secret Buffer.

const ciphertext = secretBlob.encrypt(plaintext, key, [ciphertext])

Encrypt plaintext under key. Optionally pass Buffer ciphertext to write to. Must be secretBlob.encryptLength(plaintext) long.

Returns a normal Buffer.

const byteLength = secretBlob.encryptLength(plaintext)

Returns the number of bytes required to encrypt plaintext. Simply plaintext.byteLength + secretBlob.HEADERBYTES.

const plaintext = secretBlob.decrypt(ciphertext, key, [plaintext])

Decrypt ciphertext under key. Optionally pass Buffer plaintext to write to. Must be secretBlob.decryptLength(plaintext) long.

Returns a sodium-native secret Buffer.

const byteLength = secretBlob.decryptLength(ciphertext)

Returns the number of bytes required to encrypt ciphertext. Simply ciphertext.byteLength - secretBlob.HEADERBYTES.

Constants

  • KEYBYTES: Byte length of a key
  • HEADERBYTES: Byte length of the header added to ciphertext

Install

npm install secret-blob

License

ISC