3 回答

TA貢獻1872條經驗 獲得超4個贊
最后,我找到了如何獲取所有值。
規范化 <SignedInfo><Reference> 中定義的 XML 元素。在這種情況下,它是 <soap:Body> 元素。規范化只添加了肥皂命名空間并添加了結束標簽。我在 Go 中生成這些,而 Go 從不生成自閉合標簽。
從規范化 <soap:Body> 的字符串表示中計算哈希,因為它將在請求中發送。
將計算的摘要添加到相應 <Reference> 的 <DigestValue> 中。
規范化 <SignedInfo> 并計算它的哈希值。
簽署此哈希并將值添加到 <SignedValue>。
我知道這不是通用方法,但它應該對我有用。C14N 不是必需的,因為如果您注意屬性順序并手動添加命名空間,Go 可以產生相同的結果。

TA貢獻1846條經驗 獲得超7個贊
參考 XML 示例 CZ00000019.valid.v3.xml(捷克財政當局 EET 的),規范化的 SignedInfo 是:
var signedinfoCanon
= '<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">'
+ '<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"></ec:InclusiveNamespaces>'
+ '</ds:CanonicalizationMethod>'
+ '<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"></ds:SignatureMethod>'
+ '<ds:Reference URI="#id-A72D6FD4C41B1F545F14700558808234">'
+ '<ds:Transforms>'
+ '<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">'
+ '<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""></ec:InclusiveNamespaces>'
+ '</ds:Transform>'
+ '</ds:Transforms>'
+ '<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></ds:DigestMethod>'
+ '<ds:DigestValue>4hn06sSS2yurIiUmWaV36JQJZrwbWf36sG9bOHH/ycM=</ds:DigestValue>'
+ '</ds:Reference>'
+ '</ds:SignedInfo>'

TA貢獻1824條經驗 獲得超5個贊
像這樣計算sha256
import (
"crypto/sha256"
)
var slice = []byte("test")
return sha256.Sum256(slice)
- 3 回答
- 0 關注
- 232 瀏覽
添加回答
舉報