"Sputnik" help  
Sputnik Help
HashHMacFile(<algo>, <file>, <key>, [<rawOutput>])

Description

Generates a Hash-based Message Authentication Code (HMAC) for the contents of a specified file using the specified algorithm and key.

Parameters

<algo> The hash algorithm to use (e.g., "sha256", "md5").
<file> The path to the file 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 HashHMacFile function is designed to compute a secure Hash-based Message Authentication Code (HMAC) for the contents of a specified file. It uses the provided algorithm and a secret key to ensure the integrity and authenticity of the file's content.

See HashAlgos and Hash for a list of hashes.

Related

Example

Example of usage:

say HashHMacFile("SHA256", "SputnikWin.dll", "secretKey");
say HashHMacFile("SHA256", "SputnikWin.dll", "secretKey");
say HashHMacFile("SHA256", "SputnikWin.dll", "wrongKey");
say HashHMacFile("SHA256", "SputnikWin.dll", "wrongKey");

// PRINTS
// D11F9A773706A0EB4367DAA6F846FC5F53EE0E0DD36879FC596E5A9A67AEC6D8
// D11F9A773706A0EB4367DAA6F846FC5F53EE0E0DD36879FC596E5A9A67AEC6D8
// E8C6C26F5E92EE12A7DED67D457FDE438329DA9ABA72C8A14C128AA04BB72308
// E8C6C26F5E92EE12A7DED67D457FDE438329DA9ABA72C8A14C128AA04BB72308

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