Secret Key Box Encryption
Bindings for the crypto_secretbox API. See the libsodium crypto_secretbox docs for more information.
Constants
Buffer lengths (integer)
crypto_secretbox_MACBYTES
crypto_secretbox_NONCEBYTES
crypto_secretbox_KEYBYTES
String constants (string)
crypto_secretbox_PRIMITIVE
crypto_secretbox_detached
sodium.crypto_secretbox_detached(c, mac, m, n, sk)
Encrypts a message.
c
should be abuffer
of lengthm.length
mac
should be abuffer
of lengthcrypto_secretbox_MACBYTES
m
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_secretbox_NONCEBYTES
sk
should be a secret key of lengthcrypto_secretbox_KEYBYTES
The encrypted message will be stored in c
, and the authentification code will be stored in mac
.
crypto_secretbox_easy
sodium.crypto_secretbox_easy(c, m, n, sk)
Same as crypto_secretbox_detached
, except that it encodes the mac
in the message
.
c
should be abuffer
of lengthm.length + crypto_secretbox_MACBYTES
m
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_secretbox_NONCEBYTES
sk
should be a secret key of lengthcrypto_secretbox_KEYBYTES
crypto_secretbox_open_detached
var bool = sodium.crypto_secretbox_open_detached(m, c, mac, n, sk)
Decrypts a message.
m
should be abuffer
of lengthc.length
mac
should be abuffer
of lengthcrypto_secretbox_MACBYTES
c
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_secretbox_NONCEBYTES
sk
should be a secret key
Returns true
if the ciphertext could be decrypted. Otherwise false
.
The decrypted message will be stored in m
.
crypto_secretbox_open_easy
var bool = sodium.crypto_secretbox_open_easy(m, c, n, sk)
Decrypts a message encoded with the easy method.
m
should be abuffer
of lengthc.length - crypto_secretbox_MACBYTES
c
should be abuffer
of length at leastcrypto_secretbox_MACBYTES
n
should be abuffer
of lengthcrypto_secretbox_NONCEBYTES
sk
should be a secret key
Returns true
if the ciphertext could be decrypted. Otherwise false
.
The decrypted message will be stored in m
.