SHA
Constants
Buffer lengths (integer)
crypto_hash_BYTEScrypto_hash_sha256_BYTEScrypto_hash_sha512_BYTEScrypto_hash_sha512_STATEBYTES
String constants (string)
crypto_hash_PRIMITIVE
crypto_hash
sodium.crypto_hash_(out, in)
Hashes a value to a short hash based on a key.
outshould be abufferof lengthcrypto_hash_BYTESinshould be abufferof any size
The generated short hash is stored in out.
crypto_hash_sha256
sodium.crypto_hash_sha256(out, in)
Hashes a value to a short hash based on a key.
outshould be abufferof lengthcrypto_hash_sha256_BYTESinshould be abufferof any size
The generated short hash is stored in out.
Stateful API
crypto_hash_sha256_instance
var instance = sodium.crypto_hash_sha256_instance()
Creates an instance that has stream of input data to sha256.
instance.update
instance.update(in)
Updates the instance with a new piece of data.
inshould be abufferof any size
instance.final
instance.final(out)
Finalizes the instance.
outshould be abufferof lengthcrypto_hash_sha256_BYTES
The generated hash is stored in out.
crypto_hash_sha512
sodium.crypto_hash_sha512(out, in)
Hashes a value to a short hash based on a key.
outshould be abufferof lengthcrypto_hash_sha512_BYTESinshould be abufferof any size
The generated short hash is stored in out.
crypto_hash_sha512_instance
var instance = sodium.crypto_hash_sha512_instance()
Creates an instance that has stream of input data to sha512.
instance.update
instance.update(in)
Updates the instance with a new piece of data.
inshould be abufferof any size
instance.final
instance.final(out)
Finalizes the instance.
outshould be abufferoflength crypto_hash_sha512_BYTES
The generated hash is stored in out.
Stateful API
Replaces the above instance implementation in the N-API release
crypto_hash_sha256_init
var state = Buffer.alloc(crypto_hash_sha256_STATEBYTES)
sodium.crypto_hash_sha256_init(state, [key], outlen)
Initialise a new hash state.
statemust be a buffer of lengthcrypto_hash_sha256_STATEBYTESbytes
crypto_hash_sha256_update
sodium.crypto_hash_sha256_update(state, in)
Update a hash state with a given input.
statemust be a buffer of lengthcrypto_hash_sha256_STATEBYTESbytesinshould be a abufferof any length
crypto_hash_sha256_final(state, out)
sodium.crypto_hash_sha256_final(state, out)
Finalize a given hash state and write the digest to out buffer.
statemust be a buffer of lengthcrypto_hash_sha256_STATEBYTESbytesoutmust be abufferof byte lengthcrypto_hash_sha256_BYTESbytes
crypto_hash_sha512_init
var state = Buffer.alloc(crypto_hash_sha512_STATEBYTES)
sodium.crypto_hash_sha512_init(state, [key], outlen)
Initialise a new hash state.
statemust be a buffer of lengthcrypto_hash_sha512_STATEBYTESbytes
crypto_hash_sha512_update
sodium.crypto_hash_sha512_update(state, in)
Update a hash state with a given input.
statemust be a buffer of lengthcrypto_hash_sha512_STATEBYTESbytesinshould be a abufferof any length
crypto_hash_sha512_final(state, out)
sodium.crypto_hash_sha512_final(state, out)
Finalize a given hash state and write the digest to out buffer.
statemust be a buffer of lengthcrypto_hash_sha512_STATEBYTESbytesoutmust be abufferof byte lengthcrypto_hash_sha512_BYTESbytes
