Non-Authenticated Streaming Encryption
Bindings for the crypto_stream API. See the libsodium crypto_stream docs for more information.
Constants
Buffer lengths (integer)
crypto_stream_NONCEBYTEScrypto_stream_KEYBYTEScrypto_stream_xor_STATEBYTES
String constants (string)
crypto_stream_PRIMITIVE
crypto_stream
sodium.crypto_stream(c, n, k)
Generates random data based on a nonce n and key k into the c.
cshould be abufferof any sizenshould be abufferof lengthcrypto_stream_NONCEBYTESkshould be a secret k of lengthcrypto_stream_KEYBYTES
The generated data is stored in c.
crypto_stream_xor
sodium.crypto_stream_xor(c, m, n, k)
Encrypts, but not authenticates, a m based on a nonce n and key k
cshould be abufferof lengthm.lengthmshould be abufferof any sizenshould be abufferof lengthcrypto_stream_NONCEBYTESkshould be a secret k of lengthcrypto_stream_KEYBYTES
The encrypted data is stored in c. To decrypt, swap c and m. Also supports in-place encryption where you use the same buffer as c and m.
Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor if you want to encrypt/decrypt with ChaCha20 instead.
crypto_stream_chacha20_xor
sodium.crypto_stream_chacha20_xor(c, m, n, k)
Encrypts, but not authenticates, a m based on a nonce n and key k
cshould be abufferof lengthm.lengthmshould be abufferof any sizenshould be abufferof lengthcrypto_stream_chacha20_NONCEBYTESkshould be a secret k of lengthcrypto_stream_chacha20_KEYBYTES
The encrypted data is stored in c. To decrypt, swap c and m. Also supports in-place encryption where you use the same buffer as c and m.
Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor if you want to encrypt/decrypt with ChaCha20 instead.
Instance API
crypto_stream_xor_instance
var instance = sodium.crypto_stream_xor_instance(n, k)
A streaming instance to the crypto_stream_xor API. Pass a nonce n and key k in the constructor.
Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor_instance if you want to encrypt/decrypt with ChaCha20 instead.
crypto_stream_chacha20_xor_instance
var instance = sodium.crypto_stream_chacha20_xor_instance(n, k)
A streaming instance to the crypto_stream_xor API. Pass a nonce n and key k in the constructor.
Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor_instance if you want to encrypt/decrypt with ChaCha20 instead.
instance.update
instance.update(c, m)
Encrypts the next m.
instance.final
instance.final()
Finalizes the stream. Zeros out internal state.
Stateful API
Replaces the above instance implementation in the N-API release
crypto_stream_xor_init
var state = Buffer.alloc(crypto_stream_xor_STATEBYTES)
sodium.crypto_stream_xor_init(state, n, k)
Initialise a new xor state with a nonce n and key k.
statemust be a buffer of lengthcrypto_stream_xor_STATEBYTESbytesnis must be buffer ofcrypto_stream_NONCEBYTESbyteskis must be buffer ofcrypto_stream_KEYBYTESbytes
crypto_stream_xor_update
sodium.crypto_stream_xor_update(state, c, m)
Encrypt a message m and xor the result into ciphertext c.
Update a hash state with a given input.
statemust be a buffer of lengthcrypto_stream_xor_STATEBYTESbytesmshould be abuffercshould be abufferof lengthm.byteLengthbytes
crypto_stream_xor_final(state, out)
sodium.crypto_stream_xor_final(state)
Finalize a given xor state, zeroing out the state.
statemust be a buffer of lengthcrypto_stream_xor_STATEBYTESbytes
crypto_stream_chacha20_xor_init
var state = Buffer.alloc(crypto_stream_chacha20_xor_STATEBYTES)
sodium.crypto_stream_chacha20_xor_init(state, n, k)
Initialise a new xor state with a nonce n and key k.
statemust be a buffer of lengthcrypto_stream_chacha20_xor_STATEBYTESbytesnis must be buffer ofcrypto_stream_chacha20_NONCEBYTESbyteskis must be buffer ofcrypto_stream_chacha20_KEYBYTESbytes
crypto_stream_chacha20_xor_update
sodium.crypto_stream_chacha20_xor_update(state, c, m)
Encrypt a message m and xor the result into ciphertext c.
Update a hash state with a given input.
statemust be a buffer of lengthcrypto_stream_chacha20_xor_STATEBYTESbytesmshould be abuffercshould be abufferof lengthm.byteLengthbytes
crypto_stream_chacha20_xor_final(state, out)
sodium.crypto_stream_chacha20_xor_final(state)
Finalize a given xor state, zeroing out the state.
statemust be a buffer of lengthcrypto_stream_chacha20_xor_STATEBYTESbytes
