In cryptography, an HMAC (sometimes expanded as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. As with any MAC, it may be used to simultaneously verify both the data integrity and the authenticity of a message. HMAC can provide message authentication using a shared secret instead of using digital signatures with asymmetric cryptography. It trades off the need for a complex public key infrastructure by delegating the key exchange to the communicating parties, who are responsible for establishing and using a trusted channel to agree on the key prior to communication.[1
1 Calculation of Hmac
Any cryptographic hash function, such as SHA-2 or SHA-3, may be used in the calculation of an HMAC; the resulting MAC algorithm is termed HMAC-X, where X is the hash function used (e.g. HMAC-SHA256 or HMAC-SHA3-512). The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output, and the size and quality of the key.
The hash function by default is SHA-512
<script> var kSecret = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY" var hmac256 = new Ax.crypt.Hmac("HmacSHA256"); var hmac512 = new Ax.crypt.Hmac(); var signature_256 = hmac256.calculateHMAC(hmac256.calculateHMAC(hmac256.calculateHMAC(hmac256.calculateHMAC("AWS4" + kSecret, "20150830"),"us-east-1"),"iam"),"aws4_request") console.log("signature_hmac256: " + new Ax.util.Hex().encode(signature_256)) var signature_512 = hmac512.calculateHMAC(hmac512.calculateHMAC(hmac512.calculateHMAC(hmac512.calculateHMAC("AWS4" + kSecret, "20150830"),"us-east-1"),"iam"),"aws4_request") console.log("signature_hmac512: " + new Ax.util.Hex().encode(signature_512)) </script>
signature_hmac256: c4afb1cc5771d871763a393e44b703571b55cc28424d1a5e86da6ed3c154a4b9
signature_hmac512: d9dcfd126e6dd65b1af140914af67d8b24565d096ff86571d6ef13beb91fa345fbb2b8360122cf4db215f9b284d7500da54916a9df2c1548977f5efa2ef9684a