XML-DSIG 中的 URI 和摘要计算
URI in XML-DSIG and digest calculation
我正在分析一个 XML-DSIG 文件,以便了解如何编写生成 XML-DSIGnatures 的软件代码。我遇到了这个麻烦,迫切需要帮助......
我试图从 signatures0.xml 中理解这一点(在这一点之后引用):
<Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#SignedPropertiesElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=</DigestValue>
</Reference>
signatures0.xml:
<?xml version="1.0" encoding="UTF-8"?>
<document-signatures xmlns="urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0">
<Signature Id="SignatureElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="metadata/signableMetadata0.xml" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
<XPath>ancestor-or-self::*[@ID='signature_0']</XPath>
</Transform>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>XIrOvoOM33rWvV5Fdckax/bNLOpR9RNIonkVQ22fczM=</DigestValue>
</Reference>
<Reference URI="1.docx" xmlns="http://www.w3.org/2000/09/xmldsig#">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>LtTwOA0L3mL4mswjGL3JwkumufovE/A75M4MGSUm6PQ=</DigestValue>
</Reference>
<Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#SignedPropertiesElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
EPuWjb6IeuYg32FT1tInmO7FPL1ISuluFvrPqzHdHyJ0ymgMFitaWPJQk0MV6ckgmvFwif6zpg5C
XLVJl4U+e/+AmS1AkwMf2TmnuIONuB8oLeYcDUCr+0xxlwgKSZoopzapD7ylZxIwCPTMr6BT3lx9
8EFHHVskC4wVihR0JsJWBl2YzGnBevCWpknGofa8t8vOHpTA2y9VSAu5ETXnKYF5Ms04kTy5NQ7G
kHcslw+HSAuaJolvfUd4EeqAXVFz9V7sE+akQ20fciw9QQH8gttF8bIous8dsv3/6Zmtclvbk17Q
79pI+2o7JKhZIh9ct0PHTMpU5KV6GEXxIrCb4g==
</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>
MIIKVTCCCT2gAwIBAgIOQNXCrd79knQAAAALm2IwDQYJKoZIhvcNAQEFBQAwgb0xCzAJBgNVBAYT
AkxUMUAwPgYDVQQKEzdHeXZlbnRvanUgcmVnaXN0cm8gdGFybnliYSBwcmllIExSIFZSTSAtIGku
ay4gMTg4NzU2NzY3MTEwLwYDVQQLEyhOYWNpb25hbGluaXMgc2VydGlmaWthdmltbyBjZW50cmFz
IChOU0MpMTkwNwYDVQQDEzBOYWNpb25hbGluaXMgc2VydGlmaWthdmltbyBjZW50cmFzIChJc3N1
aW5nQ0EtQikwHhcNMTQwMjA0MTM1NT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/NXH5xWC7ohKKeXzVUhnMN4WxT
</X509Certificate>
</X509Data>
</KeyInfo>
<Object>
<QualifyingProperties Target="#SignatureElem_0" xmlns="http://uri.etsi.org/01903/v1.3.2#">
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
</QualifyingProperties>
</Object>
</Signature></document-signatures>
据我了解,引用的第一个位指的是同一文件中的 SignedPropertiesElem_0 元素。我试图确定它到底指的是什么——究竟应该选择哪一段代码,稍后用于规范化,然后计算摘要值。是这样吗:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
或者这个:
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
或者这个:
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
还是它的其他部分?
我尝试了第一个,然后让它通过 StylusStudio 规范化或 http://www.soapclient.com/xmlcanon.html(两者似乎 return 相同的结果),结果是:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied></SignaturePolicyImplied>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
然后使用这些工具计算摘要值:
http://www.webutils.pl/index.php?idx=sha1
hash.online-convert.com/sha256-generator
www.freeformatter.com/message-digest.html#ad-output
它们都 return 得到了相同的结果,但该结果与 xml 文件中的结果不同:kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=
我做错了什么?我应该将 xml 文档的哪一部分复制并粘贴到规范器中,然后再粘贴到摘要计算器中?我花了几天时间尝试不同的事情并寻找答案,但一无所获......我确定我错过了一些东西,因此我请求你的帮助。
我发现结果应该是:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
规范化后我无法获得正确的摘要值的原因是因为该软件没有包含所有适用的命名空间声明,而且它也应该有 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
声明。
Web 哈希计算器的问题是 当您在 Windows 中复制和粘贴文本时,LF 换行符会被 CR+LF 替换。
我正在分析一个 XML-DSIG 文件,以便了解如何编写生成 XML-DSIGnatures 的软件代码。我遇到了这个麻烦,迫切需要帮助...... 我试图从 signatures0.xml 中理解这一点(在这一点之后引用):
<Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#SignedPropertiesElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=</DigestValue>
</Reference>
signatures0.xml:
<?xml version="1.0" encoding="UTF-8"?>
<document-signatures xmlns="urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0">
<Signature Id="SignatureElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="metadata/signableMetadata0.xml" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
<XPath>ancestor-or-self::*[@ID='signature_0']</XPath>
</Transform>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>XIrOvoOM33rWvV5Fdckax/bNLOpR9RNIonkVQ22fczM=</DigestValue>
</Reference>
<Reference URI="1.docx" xmlns="http://www.w3.org/2000/09/xmldsig#">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>LtTwOA0L3mL4mswjGL3JwkumufovE/A75M4MGSUm6PQ=</DigestValue>
</Reference>
<Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#SignedPropertiesElem_0" xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transforms xmlns="http://www.w3.org/2000/09/xmldsig#">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
EPuWjb6IeuYg32FT1tInmO7FPL1ISuluFvrPqzHdHyJ0ymgMFitaWPJQk0MV6ckgmvFwif6zpg5C
XLVJl4U+e/+AmS1AkwMf2TmnuIONuB8oLeYcDUCr+0xxlwgKSZoopzapD7ylZxIwCPTMr6BT3lx9
8EFHHVskC4wVihR0JsJWBl2YzGnBevCWpknGofa8t8vOHpTA2y9VSAu5ETXnKYF5Ms04kTy5NQ7G
kHcslw+HSAuaJolvfUd4EeqAXVFz9V7sE+akQ20fciw9QQH8gttF8bIous8dsv3/6Zmtclvbk17Q
79pI+2o7JKhZIh9ct0PHTMpU5KV6GEXxIrCb4g==
</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>
MIIKVTCCCT2gAwIBAgIOQNXCrd79knQAAAALm2IwDQYJKoZIhvcNAQEFBQAwgb0xCzAJBgNVBAYT
AkxUMUAwPgYDVQQKEzdHeXZlbnRvanUgcmVnaXN0cm8gdGFybnliYSBwcmllIExSIFZSTSAtIGku
ay4gMTg4NzU2NzY3MTEwLwYDVQQLEyhOYWNpb25hbGluaXMgc2VydGlmaWthdmltbyBjZW50cmFz
IChOU0MpMTkwNwYDVQQDEzBOYWNpb25hbGluaXMgc2VydGlmaWthdmltbyBjZW50cmFzIChJc3N1
aW5nQ0EtQikwHhcNMTQwMjA0MTM1NTUwWhcNMTcwMjAzMTM1NTUwWjBjMQswCQYDVQQGEwJMVDEZ
MBcGA1UEAwwQU0lHSVRBIFBVVFJJRU7EljESMBAGA1UEBAwJUFVUUklFTsSWMQ8wDQYDVQQqEwZT
SUdJVEExFDASBgNVBAUTCzQ4MjA5MjkwOTI5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
AQEAlsxbvBk8SKnC8MX9mJ01dsnVhdsaX/8R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wBzACAAMQA5ADkAOQAvADkAMwAvAEUAQwAgAGQBFwBsACAAQgBl
AG4AZAByAGkAagBvAHMAIABlAGwAZQBrAHQAcgBvAG4AaQBuAGkAbwAgAHAAYQByAGEBYQBvACAA
cABhAGcAcgBpAG4AZABpAG4AaQFzACAAbgB1AG8AcwB0AGEAdAFzACAASQAgAGkAcgAgAEkASQAg
AHAAcgBpAGUAZAB1AHMAIABpAHIAIABMAGkAZQB0AHUAdgBvAHMAIABlAGwAZQBrAHQAcgBvAG4A
aQBuAGkAbwAgAHAAYQByAGEBYQBvACABLwBzAHQAYQB0AHkAbQEFAC4wKAYIKwYBBQUHAgEWHGh0
dHA6Ly9uc2MudnJtLmx0L3JlcG9zaXRvcnkwHQYJKwYBBAGCNxUKBBAwDjAMBgorBgEEAYI3CgMM
MCIGCCsGAQUFBwEDBBYwFDAIBgYEAI5GAQEwCAYGBACORgEEMA0GCSqGSIb3DQEBBQUAA4IBAQAf
PXZj6QagEgswUy+wit1MdCPMbKnF5LYszPtLG/PYbtuqXstBZljRR1tZVo8DRzoVRKwM7gpNNnWF
UEtZoaafJ4uWmWWZLNSVAyaZUAJ67s2rkDPTtNtb7W9QCZJNIU2klegoY3JvDqAQzheE+Mj9HXnh
0h21Qb8MWq4lHaL99/Vk9OXSlR9WYQfbEB5zbI5kp6nVePM2cf9uOZbhZRLdDAKbL/NrSGca3S40
WZevQ1m9sdMgmobSTyuqniDXYIa7sO+QOzbMPIFuTn/izO13IK63uUBFnTImW+99PAyDx3s4Y03t
EWpXA25hWn/NXH5xWC7ohKKeXzVUhnMN4WxT
</X509Certificate>
</X509Data>
</KeyInfo>
<Object>
<QualifyingProperties Target="#SignatureElem_0" xmlns="http://uri.etsi.org/01903/v1.3.2#">
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
</QualifyingProperties>
</Object>
</Signature></document-signatures>
据我了解,引用的第一个位指的是同一文件中的 SignedPropertiesElem_0 元素。我试图确定它到底指的是什么——究竟应该选择哪一段代码,稍后用于规范化,然后计算摘要值。是这样吗:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
或者这个:
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
或者这个:
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
还是它的其他部分?
我尝试了第一个,然后让它通过 StylusStudio 规范化或 http://www.soapclient.com/xmlcanon.html(两者似乎 return 相同的结果),结果是:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod xmlns="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied></SignaturePolicyImplied>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
然后使用这些工具计算摘要值: http://www.webutils.pl/index.php?idx=sha1 hash.online-convert.com/sha256-generator www.freeformatter.com/message-digest.html#ad-output
它们都 return 得到了相同的结果,但该结果与 xml 文件中的结果不同:kOlNXyBs6oSP9hbh+4niZMNQ9OsOCzYhkSYYG4YdHQU=
我做错了什么?我应该将 xml 文档的哪一部分复制并粘贴到规范器中,然后再粘贴到摘要计算器中?我花了几天时间尝试不同的事情并寻找答案,但一无所获......我确定我错过了一些东西,因此我请求你的帮助。
我发现结果应该是:
<SignedProperties Id="SignedPropertiesElem_0">
<SignedSignatureProperties>
<SigningTime>2014-08-21T06:09:55Z</SigningTime>
<SigningCertificate>
<Cert>
<CertDigest>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" xmlns="http://www.w3.org/2000/09/xmldsig#"/>
<DigestValue xmlns="http://www.w3.org/2000/09/xmldsig#">JQ0kZvd0mtXQPA/RTuYV9iuc346tznvN9MoAd/0jNyM=</DigestValue>
</CertDigest>
<IssuerSerial>
<X509IssuerName xmlns="http://www.w3.org/2000/09/xmldsig#">CN=Nacionalinis sertifikavimo centras (IssuingCA-B),OU=Nacionalinis sertifikavimo centras (NSC),O=Gyventoju registro tarnyba prie LR VRM - i.k. 188756767,C=LT</X509IssuerName>
<X509SerialNumber xmlns="http://www.w3.org/2000/09/xmldsig#">1315010063538360283821765366094690</X509SerialNumber>
</IssuerSerial>
</Cert>
</SigningCertificate>
<SignaturePolicyIdentifier>
<SignaturePolicyImplied/>
</SignaturePolicyIdentifier>
</SignedSignatureProperties>
</SignedProperties>
规范化后我无法获得正确的摘要值的原因是因为该软件没有包含所有适用的命名空间声明,而且它也应该有 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
声明。
Web 哈希计算器的问题是 当您在 Windows 中复制和粘贴文本时,LF 换行符会被 CR+LF 替换。