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_MACBYTEScrypto_secretbox_NONCEBYTEScrypto_secretbox_KEYBYTES
String constants (string)
crypto_secretbox_PRIMITIVE
crypto_secretbox_detached
sodium.crypto_secretbox_detached(c, mac, m, n, sk)
Encrypts a message.
cshould be abufferof lengthm.lengthmacshould be abufferof lengthcrypto_secretbox_MACBYTESmshould be abufferof any lengthnshould be abufferof lengthcrypto_secretbox_NONCEBYTESskshould 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.
cshould be abufferof lengthm.length + crypto_secretbox_MACBYTESmshould be abufferof any lengthnshould be abufferof lengthcrypto_secretbox_NONCEBYTESskshould 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.
mshould be abufferof lengthc.lengthmacshould be abufferof lengthcrypto_secretbox_MACBYTEScshould be abufferof any lengthnshould be abufferof lengthcrypto_secretbox_NONCEBYTESskshould 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.
mshould be abufferof lengthc.length - crypto_secretbox_MACBYTEScshould be abufferof length at leastcrypto_secretbox_MACBYTESnshould be abufferof lengthcrypto_secretbox_NONCEBYTESskshould be a secret key
Returns true if the ciphertext could be decrypted. Otherwise false.
The decrypted message will be stored in m.
