secretbox-encoding
XSalsa20 Poly1305 codec that implements the abstract-encoding interface. Nonces are generated randomly and prepended to the ciphertext.
Installation
$ npm install secretbox-encoding
Usage
const codec = secretKey // encode a valuebuffer = codec // decode a valuevalue = codec
Example
const crypto = const Codec = const key = crypto const codec = const hello = codecconst world = codec console // 'hello world'
Custom Value Encodings
const pbs = const Message = const codec = const encoded = codecconst message = codec // { data: 'hello world' }
API
codec = require('secretbox-encoding')(secretKey[, opts])
Create a codec object from 32 byte secretKey
.
const key = cryptoconst codec =
buffer = codec.encode(value[, output[, offset]])
Encode a value using crypto_secretbox_easy into an optional output
buffer at an optional offset
defaulting to 0
. If an output
buffer is not given, one is allocated
for you and returned.
const buffer = codec
value = codec.decode(buffer[, offset])
Decode a buffer using crypto_secretbox_open_easy
at an optional offset
defaulting to 0
.
const value = codec
length = codec.encodingLength(value)
Returns the encoding length for a given value
.
const length = codec // 11
License
MIT