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>
这样
Base64.encode64(OpenSSL::Digest::SHA1.digest(@xml.search("[id=#{user_id}]").to_html)).chop
结果没问题。
当我计算<SignatureValue>
价值时,我遇到了麻烦,就像这样
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))
这个值是错误的。