Changes

Jump to navigation Jump to search
890 bytes removed ,  12:32, 8 May 2024
no edit summary
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>crypto:hmac(
$data as xs:anyAtomicType, $key as xs:anyAtomicType, $algorithm as xs:string,
$encoding as xs:string := ()
) as xs:string</pre>
|Return message authentication code (MAC) for a given string:
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
crypto:hmac('message', 'secretkey', 'md5', 'hex')
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml">
34D1E3818B347252A75A4F6D747B21C2
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>crypto:encrypt(
$data as xs:anyAtomicType, $type as xs:string, $key as xs:anyAtomicType,
$algorithm as xs:string
) as xs:base64Binary</pre>
| '''Example'''
|Encrypt input data:
<syntaxhighlight pre lang="'xquery"'>
crypto:encrypt('message', 'symmetric', 'keykeyke', 'DES')
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>crypto:decrypt(
$data as xs:anyAtomicType, $type as xs:string, $key as xs:anyAtomicType,
$algorithm as xs:string
) as xs:string</pre>
|Decrypt input data and return original string:
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
let $encrypted := crypto:encrypt('message', 'symmetric', 'keykeyke', 'DES')
return crypto:decrypt($encrypted, 'symmetric', 'keykeyke', 'DES')
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml">
message
</syntaxhighlightpre>
|}
'''XML Signature'''
<syntaxhighlight pre lang="xml">
<Signature>
<SignedInfo>
<Object/>
</Signature>
</syntaxhighlightpre>
* '''SignedInfo''' contains or references the signed data and lists algorithm information
The {{Code|generate-signature}} function allows to pass a {{Code|digital certificate}}. This certificate holds parameters that allow to access key information stored in a Java key store which is then used to sign the input document. Passing a {{Code|digital certificate}} simply helps re-using the same key pair to sign and validate data. The {{Code|digital certificate}} is passed as a node and has the following form:
<syntaxhighlight pre lang="xml">
<digital-certificate>
<keystore-type>JKS</keystore-type>
<keystore-uri>...</keystore-uri>
</digital-certificate>
</syntaxhighlightpre>
==crypto:generate-signature==
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>crypto:generate-signature(
$input as node(), $canonicalization as xs:string, $digest as xs:string, $signature as xs:string, $prefix as xs:string, $type as xs:string, $ext1 as item(), $ext2 as node()
) as node()</pre>
{{Func|crypto:generate-signature|$input as node(), $canonicalization as xs:string, $digest as xs:string, $signature as xs:string, $prefix as xs:string, $type as xs:string, $ext1 as item()|node()}}<br/>
{{Func|crypto:generate-signature|$input as node(), $canonicalization as xs:string, $digest as xs:string, $signature as xs:string, $prefix as xs:string, $type as xs:string, $ext1 as item(), $ext2 as node()|node()}}
|- valign="top"
| '''Summary'''
'''Query:'''
<syntaxhighlight pre lang="'xquery"'>
crypto:generate-signature(<a/>, '', '', '', '', '')
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight pre lang="xml">
<a>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
</Signature>
</a>
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>crypto:validate-signature(
$input-doc as node()
| '''Errors'''
|{{Error|CX0015|#Errors}} the signature element cannot be found.<br/>{{Error|CX9994|#Errors}} an unspecified problem occurs during validation.<br/>{{Error|CX9996|#Errors}} an IO exception occurs during validation.<br/>
|- valign="top"
| '''Example'''
|Validate [https://www.w3.org/TR/xmldsig-core/ XML Signature]:
 
'''Query:'''
<syntaxhighlight lang="xquery">
let $sig := crypto:generate-signature(<a/>, '', '', '', '', '')
return crypto:validate-signature($sig)
</syntaxhighlight>
 
'''Result:'''
<syntaxhighlight lang="xml">
true
</syntaxhighlight>
|}
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu