.NET SignedXml 给出错误的摘要值



>我正在尝试制作一个签名的XML文档,而我将其发送到的Web服务拒绝了它并指出签名无效。我还有一些其他的 php 代码并且可以工作,Web 服务接受 php 生成和签名的 xml,但不接受 vb.net 的 xml。我已经使 php 和 vb.net 输入 xml 完全相等,但它们仍然生成不同的摘要值。我还尝试使用在线工具来验证 xml 签名,php 签名在那里是正确的,对于 vb.net 它说摘要值是错误的。这是我在 vb 中用于计算签名的函数:

Private Function PotpisiXml(cert As X509Certificate2, ByVal rsa As RSACryptoServiceProvider, ByVal xmlStream As MemoryStream) As XmlDocument
xmlStream.Position = 0
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(xmlStream)
Dim signedXml As New SignedXml(xmlDoc)
signedXml.SigningKey = rsa
Dim reference As New Reference()
reference.Uri = "#racunId"
Dim env As New XmlDsigEnvelopedSignatureTransform()
Dim ec14n As New XmlDsigExcC14NTransform()
reference.AddTransform(env)
reference.AddTransform(ec14n)
signedXml.AddReference(reference)
Dim keyInfo As New KeyInfo()
Dim kdata As New KeyInfoX509Data(cert)
Dim xserial As X509IssuerSerial
xserial.IssuerName = cert.IssuerName.Name
xserial.SerialNumber = cert.SerialNumber
kdata.AddIssuerSerial(xserial.IssuerName, xserial.SerialNumber)
keyInfo.AddClause(kdata)
signedXml.ComputeSignature()
signedXml.KeyInfo = keyInfo
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, True))
Return xmlDoc
End Function

vb.net 生成 xml:https://pastebin.com/jrzLsv4k

php 生成的 xml: https://pastebin.com/kbsE2PH7

对于两个代码,进入签名的 xmlDoc 完全相同。两端的编码均为 UTF-8。

我已经通过删除过程中所有空格和换行符来解决此问题。

相关内容

  • 没有找到相关文章

最新更新