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_PUBLICKEYBYTES
crypto_box_SECRETKEYBYTES
crypto_box_SEEDBYTES
crypto_box_MACBYTES
crypto_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
.
pk
should be abuffer
of lengthcrypto_box_PUBLICKEYBYTES
sk
should be abuffer
of lengthcrypto_box_SECRETKEYBYTES
seed
should be abuffer
of 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.
pk
should be abuffer
of lengthcrypto_box_PUBLICKEYBYTES
sk
should be abuffer
of 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.
c
should be abuffer
of lengthm.length
mac
should be abuffer
of lengthcrypto_box_MACBYTES
m
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_box_NONCEBYTES
pk
should be a public keysk
should 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.
c
should be abuffer
of lengthm.length + crypto_box_MACBYTES
m
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_box_NONCEBYTES
pk
should be a public keysk
should 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
.
m
should be abuffer
of lengthc.length
mac
should be abuffer
of lengthcrypto_box_MACBYTES
c
should be abuffer
of any lengthn
should be abuffer
of lengthcrypto_box_NONCEBYTES
pk
should be a public keysk
should 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.
m
should be abuffer
of lengthc.length - crypto_box_MACBYTES
c
should be abuffer
of length at leastcrypto_box_MACBYTES
n
should be abuffer
of lengthcrypto_box_NONCEBYTES
pk
should be a public keysk
should be a secret key
Returns true
if the message could be decrypted. Otherwise false
.
The decrypted message will be stored in m
.