The hmac() Function
Syntax
Copy Code | |
---|---|
string hmac(string, string, string, string?) |
Description
This function accepts a string for a key or shared secret, a string of data, a string indicating a cryptographic hashing algorithm, and an author-optional string indicating an encoding method. The key and data strings are serialized as UTF-8, and they are subjected to the HMAC algorithm and parameterized by the the hash algorithm indicated by the third parameter. The result is encoded with the method indicated by the fourth parameter, and the result is returned by the function.
The following table presents the keywords for the third string parameter and the corresponding hash algorithms being used:
Keyword | Hash Algorithm |
---|---|
MD5 | The MD5 hash algorithm |
SHA-1 | The SHA-1 hash algorithm |
SHA-256 | The SHA-256 hash algorithm |
SHA-384 | The SHA-384 hash algorithm |
SHA-512 | The SHA-512 hash algorithm |
The fourth string parameter, specifying the encoding method, accepts the values hex and base64. If the parameter is missing, then the default is base64.
Example
XML | Copy Code |
---|---|
<xforms:output value="hmac('key','abcdef', 'SHA-256', 'base64')"> <xforms:label>SHA-256 base64</xforms:label> </xforms:output> <xforms:output value="hmac('key','abcdef', 'SHA-256', 'hex')"> <xforms:label>SHA-256 hex</xforms:label> </xforms:output> <xforms:output value="hmac('key','abcdef', 'MD5', 'hex')"> <xforms:label>MD5 hex</xforms:label> </xforms:output> |
Specification
Link to the XForms specification: the hmac() function.