下面應該是一個xQuery 1.0安全解決方案。它可能更緊湊,但留下這樣的全面審查。
xquery version "1.0";
declare function local:encrypt($node){
'an encrypted value'
};
declare function local:decrypt($node){
'a decrypted value'
};
declare function local:traverse-and-encrypt($nodes as node()*) as node()*{
for $n in $nodes
return if($n/@encrypted = 'true')
then element{fn:node-name($n)}{
for $a in $n/@*
return if(fn:local-name($a) = 'encrypted')
then attribute {'encrypted'} {'false'}
else $a,
local:decrypt($n/text())
}
else if($n/@encrypted = 'false')
then element{fn:node-name($n)}{
for $a in $n/@*
return if(fn:local-name($a) = 'encrypted')
then attribute {'encrypted'} {'true'}
else $a,
local:encrypt($n/text())
}
else element{fn:node-name($n)}{
$n/@*,
$n/text(),
for $child in $n/*
return local:traverse-and-encrypt($child)
}
};
let $doc :=
<books>
<book>
<title encrypted="true">0234534rdf;skdlfsd</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title encrypted="false">Another book</title>
<author test='testing attributes'>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</books>
return local:traverse-and-encrypt($doc)
回報:
<books>
<book>
<title encrypted="false">a decrypted value</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title encrypted="true">an encrypted value</title>
<author test="testing attributes">J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</books>
這是在DB2 for z/OS上或在Linux/Unix/Windows的?你試過什麼了? –
因此,您想要替換一個元素,該元素(正確地)說明其內容是使用內容被解密但說明(錯誤地)內容仍然被加密的元素加密的元素?找到指定這種行爲的設計師並執行嚴重的諮詢。 –
代碼將作爲數據庫包在數據庫中運行,所以我一直在嘗試使用xquery,但是我對如何解決這個問題有點難以理解。主要的問題是,我不會事先沒有加密哪些柱子,所以程序需要是通用的。 –