The crypto.createHmac() method is used to create an Hmac object that uses the stated ‘algorithm’ and ‘key’.
crypto.createHmac( algorithm, key, options )
Parameters: This method accept three parameters as mentioned avobe and described below:
- algorithm: It is dependent on the accessible algorithms which are favored by the version of OpenSSL on the platform. It returns string. The examples are sha256, sha512, etc.
- key: It is the HMAC key which is used to create the cryptographic HMAC hash. It returns string, Buffer, TypedArray, DataView, or KeyObject. And if it is a KeyObject, then its type must be secret.
- options: It is optional parameter and used to control stream behavior. It returns an object.
Return Type: It returns Hmac object.
Below examples illustrate the use of crypto.createHmac() method in Node.js:
Program done! The hmac object returns: 4605d44703c2620fc2574c9a9216bd3267457324 /run_dir/interp.js