Compute HMAC SHA message digests.
Secret key
Message to be hashed
HMAC digest using raw bytes as input and output.
Prefer digest when your key and message are UTF-8 strings. This function
(digestBytes) is unsafe, in that it does not ensure each Int fits into an
8-bit value.
Prefer digestBytes when you need to chain digests. That is, to use the output
of a digest as the input (either key or message) to another digest.
See the AWS Signature V4 Example for an explanation of the following algorithm:
import Word.Bytes as Bytes
import Word.Hex as Hex
let
digest =
\message key ->
Crypto.HMAC.digestBytes sha256
key
(Bytes.fromUTF8 message)
in
("AWS4" ++ "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY")
|> Bytes.fromUTF8
|> digest "20150830"
|> digest "us-east-1"
|> digest "service"
|> digest "aws4_request"
|> digest "AWS4-HMAC-SHA256\n20150830T123600Z\n20150830/us-east-1/service/aws4_request\n816cd5b414d056048ba4f7c5386d6e0533120fb1fcfa93762cf0fc39e2cf19e0"
|> Hex.fromByteList
--> "b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500"Secret key, as a list of bytes.
You must ensure each Int is an 8-bit value.
Message to be hashed, as a list of bytes.
You must ensure each Int is an 8-bit value.
Type of hash algorithm.
Use SHA512/224 as the hash algorithm.
Use SHA512/256 as the hash algorithm.
HMAC digest using UTF-8 strings as input.
Outputs bytes encoded as a hexadecimal string. Prefer this function when your key and message are UTF-8 encoded strings.