xml = '<?xml version="1.0" encoding="UTF-8"?>
<User>
<Uer id="user_id">
<Code>1111</Code>
<ID>0000000111</ID>
</Uer>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference Type="http://www.w3.org/2000/09/xmldsig#Object" URI="#user_id">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>mwsSKYG+Q/krE54kcNpEGtXnQ+w=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>???????????????????</SignatureValue>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
.........
</X509Data>
</KeyInfo>
</Signature>
</User>'
@xml = Nokogiri::XML.parse(xml)
我有一個xml,需要xml簽名。 <DigestValue>
這樣的Ruby中的XML數字簽名
Base64.encode64(OpenSSL::Digest::SHA1.digest(@xml.search("[id=#{user_id}]").to_html)).chop
並且結果是OK。
當我計算3210值我得到的麻煩,這樣
p = OpenSSL::PKCS12.new(File.read("/Path/signCert.p12"),"123456")
Base64.encode64(OpenSSL::PKey::RSA.new(p.key).sign(OpenSSL::Digest::SHA1.new, tmpxml.search("SignedInfo").to_html))
,該值是錯誤的。