SHA
Constants
Buffer lengths (integer)
crypto_hash_BYTES
crypto_hash_sha256_BYTES
crypto_hash_sha512_BYTES
crypto_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.
out
should be abuffer
of lengthcrypto_hash_BYTES
in
should be abuffer
of 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.
out
should be abuffer
of lengthcrypto_hash_sha256_BYTES
in
should be abuffer
of 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.
in
should be abuffer
of any size
instance.final
instance.final(out)
Finalizes the instance.
out
should be abuffer
of 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.
out
should be abuffer
of lengthcrypto_hash_sha512_BYTES
in
should be abuffer
of 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.
in
should be abuffer
of any size
instance.final
instance.final(out)
Finalizes the instance.
out
should be abuffer
oflength 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.
state
must be a buffer of lengthcrypto_hash_sha256_STATEBYTES
bytes
crypto_hash_sha256_update
sodium.crypto_hash_sha256_update(state, in)
Update a hash state with a given input.
state
must be a buffer of lengthcrypto_hash_sha256_STATEBYTES
bytesin
should be a abuffer
of 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.
state
must be a buffer of lengthcrypto_hash_sha256_STATEBYTES
bytesout
must be abuffer
of byte lengthcrypto_hash_sha256_BYTES
bytes
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.
state
must be a buffer of lengthcrypto_hash_sha512_STATEBYTES
bytes
crypto_hash_sha512_update
sodium.crypto_hash_sha512_update(state, in)
Update a hash state with a given input.
state
must be a buffer of lengthcrypto_hash_sha512_STATEBYTES
bytesin
should be a abuffer
of 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.
state
must be a buffer of lengthcrypto_hash_sha512_STATEBYTES
bytesout
must be abuffer
of byte lengthcrypto_hash_sha512_BYTES
bytes