XQuery/數字簽名
外觀
< XQuery
您想要驗證傳送給您的文件是否未被修改。
我們將使用 W3C 數字簽名標準。我們將使用標準 Java 函式來簽署和驗證文件的簽名。
警告:該程式尚不可用
要使用該函式,您需要建立一個本地金鑰庫來儲存您的資訊。在生產系統中,金鑰庫儲存在內部伺服器上,但在本示例中,我們將將其儲存在 eXist 資料庫中作為二進位制檔案。
以下 shell 命令顯示瞭如何使用 Java JRE 附帶的 keytool 程式生成金鑰庫檔案
/usr/java/bin/keytool -genkeypair -dname "cn=Test Certificate, ou=MyDivision, o=MyCompany, c=US"
-alias eXist -keypass kpi135 -keystore /tmp/keystore.pem -storepass ab987c -
validity 180
執行此檔案後,將 /tmp/keystore.pem 檔案放入您的檔案系統 /db/test/dig-sig/keystore.pem 中
我們將向 $EXIST_HOME/lib/extensions 區域新增一個自定義 jar 檔案,稱為 x-krypt.jar。載入此檔案後,我們需要將以下行新增到 $EXIST_HOME/conf.xml 的 xquery/builtin-modules 區域(大約第 780 行)
<module class="ro.kuberam.xcrypt.XcryptModule"
uri="http://kuberam.ro/x-crypt" />
重新啟動伺服器後,可以執行以下操作
xquery version "1.0";
let $keystore-file-path := '/db/test/dig-sig/keystore.txt'
return
if ( not(util:binary-doc-available($keystore-file-path)) )
then
<error><message>Keystore File {$keystore-file-path} Not Available</message></error>
else
let $doc := <data><a>1</a><b>7</b><c/><c/></data>
let $certificate-details :=
<digital-certificate>
<keystore-type>JKS</keystore-type>
<keystore-name>{$keystore-file-path}</keystore-name>
<keystore-password>ab987c</keystore-password>
<key-alias>eXist</key-alias>
<private-key-password>kpi135</private-key-password>
</digital-certificate>
let $signed-doc := x-crypt:generate-signature($doc, "inclusive", "", "DSA_SHA1", "ds", "enveloped", $certificate-details )
return
<results>
<doc>{$doc}</doc>
<keystore-file-path>{$keystore-file-path}</keystore-file-path>
</results>
用於簽署 XML 文件的相同過程可用於驗證其簽名。