HMAC_MD5

The HMAC_MD5 function takes two Strings as input, a base string and a key, and returns the hash of the base string as a Hex- or Base64-encoded string, arrived at via the HMAC-MD5 algorithm.

This function requires two Strings as input: a base string and key. As an option, it also accepts another string that defines if Hex or Base64 encoding will to be used to calculate the output: a string that gives the hash of the first input, as calculated by the HMAC-MD5 algorithm.

Declaration

HMAC_MD5(base_string, key, encode) -> hash

Parameters

base_string (required, type:string) Any string.

key (required, type:string) The key used in the calculation of the HMAC.

encode (optional, type:string, default: "Hex")

The string "Hex" or "Base64". This defines if the hash of the base string will be Hex- or Base64-encoded, respectively.

If no value is given for encode, HMAC_MD5 will return the Hex-encoded hash. If a value other than "Hex" or "Base64" is given for encode, HMAC_MD5 will throw an error.

Return Values

hash(type: string) The hash of the input as calculated by the HMAC-MD5 algorithm.

Examples

The following example uses the key "111" to calculate Hex-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm:

HMAC_MD5("This is a string.", "111") => "8884c1b44e9d3ffa77488052a4aed804"

The following example also uses the key "111" to return the Hex-encoded hash of the string "This is a string." as calculated by the HMAC-MD5 algorithm. Note that it returns the same output as the above example; there is no difference in output between explicitly defining "Hex" as the value for encode and not defining encode at all:

HMAC_MD5("This is a string.", "111", "Hex") => "8884c1b44e9d3ffa77488052a4aed804"

The following example uses the key "111" to calculate Base64-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm. Note how this differs from the first two examples:

HMAC_MD5("This is a string.", "111", "Base64") => "E1YrRxGCMRtu6o0kEQPo8A=="

The following example uses the key "ai4nga0" to calculate Hex-encoded hash of the string "This is a string." according to the HMAC-MD5 algorithm. Note how the output is impacted by the key:

HMAC_MD5("This is a string.", "ai4nga0") => "0edb9ad5d485a34c59b26da0c564ea8c"

Last updated