|<code><b>crypto:hmac</b>($message as xs:string(), $secret-key as xs:string(), algorithm as xs:string()) as xs:string()</code><br/><code><b>crypto:hmac</b>($message as xs:string(), $secret-key as xs:string(), algorithm as xs:string(), $encoding as xs:string()) as xs:string()</code>
|-
| valign='top' | '''Summary'''
|Creates a message authentication code via a cryptographic hash function and a secret key. <br/>
<code>$encoding</code> must either be <code>hex</code>, <code>base64</code> or the empty string and specifies the encoding of the returned authentication code. <b>Default is <code>base64</code></b>.<br/>
<code>$algorithm</code> describes the hash algorithm which is used for encryption. Currently supported are <code>md5</code>, <code>sha1</code>, <code>sha256</code>, <code>sha384</code>, <code>sha512</code>. <b>Default is <code>md5</code></b>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0013]]</b> is raised if the specified hashing algorithm is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0014]]</b> is raised if the specified encoding method is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0019]]</b> is raised if the specified secret key is invalid.<br/>
|-
| valign='top' | '''Example'''
|'''Returns the message authentication code (MAC) for a given string.'''
|<code><b>crypto:encrypt</b>($input as xs:string(), $encryption-type as xs:string(), $secret-key as xs:string(), $cryptographic-algorithm as xs:string()) as xs:string()</code>
|-
| valign='top' | '''Summary'''
|Encrypts the given input string.<br/>
<code>$encryption-type</code> must be <code>symmetric</code>, as asymmetric encryption is not supported so far. <b>Default is <code>symmetric</code></b>.<br/>
<code>$cryptographic-algorithm</code> must either be <code>DES</code> or <code>AES</code>. Other algorithms are not supported so far, but, of course, can be added on demand. <b>Default is <code>DES</code></b>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0016]]</b> is raised if padding problems arise.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0017]]</b> is raised if padding is incorrect.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0021]]</b> is raised if the specified encryption algorithm is not supported.<br/>
|-
| valign='top' | '''Example'''
|'''Encrypts input data.'''
|<code><b>crypto:decrypt</b>($input as xs:string(), $decryption-type as xs:string(), $secret-key as xs:string(), $cryptographic-algorithm as xs:string()) as xs:string()</code>
|-
| valign='top' | '''Summary'''
|Decrypts the encrypted <code>$input</code>.<br/>
<code>$decryption-type</code> must be <code>symmetric</code>. An option for asymmetric encryption will most likely be added with another version of BaseX. <b>Default is <code>symmetric</code></b>.<br/>
<code>$cryptographic-algorithm</code> must either be <code>DES</code> or <code>AES</code>. Other algorithms are not supported so far, but, of course, can be added on demand. <b>Default is <code>DES</code></b>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0016]]</b> is raised if padding problems arise.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0017]]</b> is raised if padding is incorrect.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0021]]</b> is raised if the specified encryption algorithm is not supported.<br/>
|-
| valign='top' | '''Example'''
|'''Decrypts input data and returns the original string.'''
|<code><b>crypto:generate-signature</b>($input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string()) as node()</code><br/><code><b>crypto:generate-signature</b>($input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $xpath-expression as xs:string()) as node()</code><br/><code><b>crypto:generate-signature</b>($input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $digital-certificate as node()) as node()</code><br/><code><b>crypto:generate-signature</b>($input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $xpath-expression as xs:string(), $digital-certificate as node()) as node()</code>
|-
| valign='top' | '''Summary'''
|<code>$canonicalization-algorithm</code> must either be <code>inclusive-with-comments</code>, <code>inclusive</code>, <code>exclusive-with-comments</code> or <code>exclusive</code>. <b>Default is <code>inclusive-with-comments</code></b>.<br/>
<code>$digest-algorithm</code> must be one of the following: <code>SHA1</code>, <code>SHA256</code> or <code>SHA512</code>. <b>Default is <code>SHA1</code></b>.<br/>
<code>$digital-certificate</code> is the digitial certificate used to sign the input document.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0001]]</b> is raised if the canonicalization algorithm is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0002]]</b> is raised if the digest algorithm is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0028]]</b> is raised if the signature type is not supported.<br/>
|-
| valign='top' | '''Example'''
|'''Generates an [http://www.w3.org/TR/xmldsig-core/ XML Signature].'''
|<code><b>crypto:validate-signature</b>($input-doc as node()) as xs:boolean()</code>
|-
| valign='top' | '''Summary'''
|Checks if the given node contains a <code>Signature</code> element and whether the signature is valid. In this case <code>true</code> is returned. If the signature is invalid the function returns <code>false</code>.
|-
| valign='top' | '''Errors'''
|<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0015]]</b> is raised if the signature element cannot be found.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX9994]]</b> is raised if an unspecified problem occurs during validation.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX9996]]</b> is raised if an IO exception occurs during validation.<br/>
|-
| valign='top' | '''Example'''
|'''Validates an [http://www.w3.org/TR/xmldsig-core/ XML Signature].'''