SHA1摘要或Xades SignedProperties的计算不起作用
本文关键字:计算 不起作用 SignedProperties Xades SHA1 | 更新日期: 2023-09-27 18:23:52
我有以下XML文件:
<xad:SignedProperties Id="Sig_20151117_172752_SP">
<xad:SignedSignatureProperties>
<xad:SigningTime>2015-11-17T16:27:59Z</xad:SigningTime>
<xad:SigningCertificate>
<xad:Cert>
<xad:CertDigest>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>vkVMqVMRsiSbo3Zgvk9sTfVtRDs=</ds:DigestValue>
</xad:CertDigest>
<xad:IssuerSerial>
<ds:X509IssuerName>CN=CERTEUROPE ADVANCED CA V4, OU=0002 434202180, O=Certeurope, C=FR</ds:X509IssuerName>
<ds:X509SerialNumber>747583</ds:X509SerialNumber>
</xad:IssuerSerial>
</xad:Cert>
</xad:SigningCertificate>
<xad:SignaturePolicyIdentifier>
<xad:SignaturePolicyId>
<xad:SigPolicyId>
<xad:Identifier>1234567</xad:Identifier>
<xad:Description>Description de la politique de signature numérique</xad:Description>
</xad:SigPolicyId>
<xad:SigPolicyHash>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>ZXphcmxramhxZGY=</ds:DigestValue>
</xad:SigPolicyHash>
<xad:SigPolicyQualifiers>
<xad:SigPolicyQualifier>
<xad:SPURI>1234567</xad:SPURI>
</xad:SigPolicyQualifier>
</xad:SigPolicyQualifiers>
</xad:SignaturePolicyId>
</xad:SignaturePolicyIdentifier>
<xad:SignerRole>
<xad:ClaimedRoles/>
</xad:SignerRole>
</xad:SignedSignatureProperties>
<xad:SignedDataObjectProperties>
<xad:CommitmentTypeIndication>
<xad:CommitmentTypeId>
<xad:Identifier>1.2.840.113549.1.9.16.6.1</xad:Identifier>
<xad:Description>1.2.840.113549.1.9.16.6.1</xad:Description>
</xad:CommitmentTypeId>
<xad:ObjectReference>#D0-Reference</xad:ObjectReference>
</xad:CommitmentTypeIndication>
</xad:SignedDataObjectProperties>
</xad:SignedProperties>
(一开始,我特意缩进了它的线性XML)。
我需要获得以下摘要:
<ds:Reference Id="Sig_20151117_172752_SP-Reference" Type="http://uri.etsi.org/01903/#SignedProperties" URI="#Sig_20151117_172752_SP">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>euEROs8DacsBe3xqXBY5T+M07AI=</ds:DigestValue>
</ds:Reference>
我正在使用规范化C14N来做到这一点。
我试图将这些名称空间添加到第一个标签中:
xmlns:xad="http://uri.etsi.org/01903/v1.3.2#"xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
按以下顺序:
或
但这些尝试都不会奏效。有什么东西不见了吗?(以下是我用来计算SHA-1摘要的C#方法:
public string CalculateHashSHA1(string input)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
return Convert.ToBase64String(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)));
}
}
编辑:
- 源文件在这里:https://1fichier.com/?y9spk6g2zk
- 带有缩进的源文件在那里:https://1fichier.com/?11r0i8izzt
我正在尝试获取此摘要:euEROs8DacsBe3xqXBY5T+M07AI=
事实上,我需要使用这个方法:
XmlDsigExcC14NTransform innerTransform = new XmlDsigExcC14NTransform(false);
结果是正确的。