Creates and returns an Hmac object that uses the given algorithm and key.
Optional options argument controls stream behavior.
The algorithm is dependent on the available algorithms supported by the
version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc.
On recent releases of OpenSSL, openssl list -digest-algorithms will
display the available digest algorithms.
The key is the HMAC key used to generate the cryptographic HMAC hash. If it is
a KeyObject, its type must be secret. If it is a string, please consider caveats when using strings as inputs to cryptographic APIs. If it was
obtained from a cryptographically secure source of entropy, such as randomBytes or generateKey, its length should not
exceed the block size of algorithm (e.g., 512 bits for SHA-256).
constinput = createReadStream(filename); input.on('readable', () => { // Only one element is going to be produced by the // hash stream. constdata = input.read(); if (data) hmac.update(data); else { console.log(`${hmac.digest('hex')}${filename}`); } });
Creates and returns an
Hmac
object that uses the givenalgorithm
andkey
. Optionaloptions
argument controls stream behavior.The
algorithm
is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are'sha256'
,'sha512'
, etc. On recent releases of OpenSSL,openssl list -digest-algorithms
will display the available digest algorithms.The
key
is the HMAC key used to generate the cryptographic HMAC hash. If it is aKeyObject
, its type must besecret
. If it is a string, please considercaveats when using strings as inputs to cryptographic APIs
. If it was obtained from a cryptographically secure source of entropy, such as randomBytes or generateKey, its length should not exceed the block size ofalgorithm
(e.g., 512 bits for SHA-256).Example: generating the sha256 HMAC of a file