Performs an HMAC-SHA-256 hash function
Agent
Name | Type | Description |
---|---|---|
dataToHash | String or blob |
The data to which the hash function will be applied
|
key | String or blob |
The hash key
|
Blob — the hashed data (32 bytes)
This method performs an HMAC-SHA256 hash using the input data and key. Because the returned data is a blob, it is not uncommon to Base64 encode it.
A simple example of HMAC-SHA-256 hashing.
function blobToHexString(data) { | |
local s = "0x"; | |
foreach (b in data) s += format("%02X", b); | |
return s; | |
} | |
function testHash() { | |
local data = "The quick brown fox jumps over the lazy dog"; | |
local key = "key"; | |
local hash = http.hash.hmacsha256(data, key); | |
server.log("Hex: " + blobToHexString(hash)); | |
server.log("Base64: " + http.base64encode(hash)); | |
} | |
testHash(); |