The digest() Function

Release 2.0 - ...

Syntax

  CopyCode image Copy Code
string digest(string, string, string?)

Description

This function accepts a string of data, a string indicating a cryptographic hashing algorithm, and an author-optional string indicating an encoding method. The data string is serialized as UTF-8, the hash value is then computed using the indicated hash algorithm, and the hash value is then encoded by the indicated method, and the result is returned by the function.

The following table presents the keywords for the second 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 third string parameter, specifying the encoding method, accepts the values hex and base64. If the parameter is missing, then the default is base64.

Example

XML CopyCode image Copy Code
<xforms:output value="digest('abcdef', 'SHA-256', 'base64')">
   <xforms:label>SHA-256 base64</xforms:label>
</xforms:output>
<xforms:output value="digest('abcdef', 'SHA-256', 'hex')">
   <xforms:label>SHA-256 hex</xforms:label>
</xforms:output>
<xforms:output value="digest('abcdef', 'MD5', 'hex')">
   <xforms:label>MD5 hex</xforms:label>
</xforms:output>

Specification

Link to the XForms specification: the digest() function.