Public/Secret Key Box Encryption
Bindings for the crypto_box API. See the libsodium crypto_box docs for more information.
Constants
Buffer lengths (integer)
crypto_box_PUBLICKEYBYTEScrypto_box_SECRETKEYBYTEScrypto_box_SEEDBYTEScrypto_box_MACBYTEScrypto_box_NONCEBYTES
String constants (string)
crypto_box_PRIMITIVE
crypto_box_seed_keypair
sodium.crypto_box_seed_keypair(pk, sk, seed)
Creates a new keypair based on a seed.
pkshould be abufferof lengthcrypto_box_PUBLICKEYBYTESskshould be abufferof lengthcrypto_box_SECRETKEYBYTESseedshould be abufferof lengthcrypto_box_SEEDBYTES
The generated public and secret key will be stored in buffer's.
crypto_box_keypair
sodium.crypto_box_keypair(pk, sk)
Creates a new keypair.
pkshould be abufferof lengthcrypto_box_PUBLICKEYBYTESskshould be abufferof lengthcrypto_box_SECRETKEYBYTES
The generated public and secret key will be stored in buffer's.
crypto_box_detached
sodium.crypto_box_detached(c, mac, m, n, pk, sk)
Encrypts a message.
cshould be abufferof lengthm.lengthmacshould be abufferof lengthcrypto_box_MACBYTESmshould be abufferof any lengthnshould be abufferof lengthcrypto_box_NONCEBYTESpkshould be a public keyskshould be a secret key
The encrypted message will be stored in c and the authentification code will be stored in mac.
crypto_box_easy
sodium.crypto_box_easy(c, m, n, pk, sk)
Same as crypto_box_detached, except that it encodes the mac in the message.
cshould be abufferof lengthm.length + crypto_box_MACBYTESmshould be abufferof any lengthnshould be abufferof lengthcrypto_box_NONCEBYTESpkshould be a public keyskshould be a secret key
The encrypted message and authentification code will be stored in c.
crypto_box_open_detached
var bool = sodium.crypto_box_open_detached(m, c, mac, n, pk, sk)
Decrypts ciphertext c into message m.
mshould be abufferof lengthc.lengthmacshould be abufferof lengthcrypto_box_MACBYTEScshould be abufferof any lengthnshould be abufferof lengthcrypto_box_NONCEBYTESpkshould be a public keyskshould be a secret key
Returns true if the message could be decrypted. Otherwise false.
The decrypted message will be stored in m.
crypto_box_open_easy
var bool = sodium.crypto_box_open_easy(m, c, n, pk, sk)
Decrypts a ciphertext encoded with the easy method.
mshould be abufferof lengthc.length - crypto_box_MACBYTEScshould be abufferof length at leastcrypto_box_MACBYTESnshould be abufferof lengthcrypto_box_NONCEBYTESpkshould be a public keyskshould be a secret key
Returns true if the message could be decrypted. Otherwise false.
The decrypted message will be stored in m.
