【问题标题】:How do I decide the `DigestValue`, `SignatureValue` and `RSAKeyValue` for digital signing of XML如何确定用于 XML 数字签名的 `DigestValue`、`SignatureValue` 和 `RSAKeyValue`
【发布时间】:2016-06-03 21:21:26
【问题描述】:

我正在做一个项目,我需要验证 xml 是否经过数字签名。 我真的很难尝试验证 XML 的关键值以供关注

    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
      <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <Reference URI=**Some URI Value**>
        <Transforms>
          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">

          </Transform>
        </Transforms>
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
        <DigestValue>**Some Digest Value**</DigestValue>
      </Reference>
    </SignedInfo>
    <SignatureValue>**Some Signature Value**</SignatureValue>
  <KeyInfo xmlns:type="http://www.w3.org/2000/09/xmldsig#RSAKeyValue">  
    <RSAKeyValue><Modulus>**Some RSA Key Value**</Modulus>  
     <Exponent>AQAB</Exponent>
    </RSAKeyValue>
   </KeyInfo >  
</Signature>

我无法找出如何获取

的值
  1. Reference URI
  2. Digest Value
  3. Signature Value
  4. RSA Modulus Value

谁能告诉我如何获得上述所有值? 在 XML Validation 中使用这些组合背后的逻辑是什么?

我使用C# 来检查验证。 你可以在我之前的问题中检查 c# 的代码

  1. How to validate XML for following code

提前致谢。

【问题讨论】:

    标签: c# xml


    【解决方案1】:

    如果您只想检查值是否存在,只需使用一些 XML 操作类,如 XDocument。

    如果你想验证签名你需要明白这一点:

    1. 发行者生成文档的 HASH 并放在上面(这是 DigestValue)
    2. 发行人用他的私钥加密这个 HASH 并放入文档(这是 SignatureValue)
    3. 用户将其证书与文档一起发送(这是 X509Certificate 字段)。

    所以如果你想检查签名是否有效,你需要用他的公钥对 SignatureValue 进行解密,然后与 DigestValue 进行比较。如果两者相等,则您的文档是可以的,如果不是,则可能发生了两件事。或者文档在处理过程中被修改,或者公钥与加密文档的私钥不对应。

    【讨论】:

      猜你喜欢
      • 2011-01-10
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      相关资源
      最近更新 更多