开发者社区> 镜像站> NPM> secret-blob
secret-blob
Tiny module for easy encryption of Buffers
Last updated 6 months ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install secret-blob 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.0                                ...           latest (6 months ago)

3 Versions

  • 1.1.0                                ...           6 months ago
  • 1.0.1                                ...           6 months ago
  • 1.0.0                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None