"Sputnik" help  
Sputnik Help
HashHMac(<algo>, <binary>, <key>, <rawOutput>)

Description

Generates a Hash-based Message Authentication Code (HMAC) for the provided binary data using the specified algorithm and key.

Parameters

<algo> The hash algorithm to use (e.g., "sha256", "md5").
<binary> The binary data for which the HMAC is generated.
<key> The secret key used in the HMAC calculation.
[<rawOutput>] Optional. If set to true, returns a binary HMAC; otherwise, returns a string HMAC. Default is a string HMAC.

Return Value

Success: Returns the HMAC value as either a string or binary, based on the rawOutput parameter.
Failure: Returns an empty string or binary (depending on <rawOutput>) if the hashing process encounters an issue.

Remarks

The HashHMac function is useful for generating a secure and verifiable hash-based message authentication code (HMAC) using a secret key. The choice of algorithm and key is crucial for the security of the HMAC.

See HashAlgos and Hash for a list of hashes.

Related

Hash

Example

Example of usage:

say HashHMac("SHA256", "Secret Data", "secretKey");
say HashHMac("SHA256", "Secret Data", "secretKey");
say HashHMac("SHA256", "Secret Data", "wrongKey");
say HashHMac("SHA256", "Secret Data", "wrongKey");

// PRINTS
// 95D0433A2DB80722558DFD616273097D71A7958585956D7D363E7708A088A124
// 95D0433A2DB80722558DFD616273097D71A7958585956D7D363E7708A088A124
// 8193E3DA83635DBCFCBD32658D65410DBCD5D13E52729C7EC9943838DD7E57DB
// 8193E3DA83635DBCFCBD32658D65410DBCD5D13E52729C7EC9943838DD7E57DB

In this example, the HashHMac function in Sputnik is employed to compute Hash-based Message Authentication Codes (HMACs) for a given set of binary data, using different secret keys. The provided binary data, "Secret Data," is hashed with the SHA-256 algorithm and two distinct keys, "secretKey" and "wrongKey." Remarkably, when the correct key is used, the resulting HMAC remains consistent across multiple invocations, evidenced by the identical hash values in the first and second calls. Conversely, when an incorrect key, "wrongKey," is supplied, the HMAC differs from the correct key, demonstrating the cryptographic strength of HMACs and their sensitivity to key variations. This behavior highlights the role of the secret key in HMAC computation, underscoring its importance for data integrity and authentication.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org