SignedXml 规范化方法 - http://www.w3.org/2006/12/xml-c14n11

问题描述 投票:0回答:2

是否可以使用 http://www.w3.org/2006/12/xml-c14n11 CanonicalizationMethod 与 SignedXml?

SignedXml signedXml = new SignedXml(xmlDoc);
signedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2006/12/xml-c14n11";

正在投掷

System.Security.Cryptography.CryptographicException: Could not create the XML tr
ansformation identified by the URI http://www.w3.org/2006/12/xml-c14n11.

谢谢您!

c# digital-signature signedxml
2个回答
6
投票

看起来.NET还没有实现。

https://msdn.microsoft.com/en-us/library/system.security.cryptography.xml.signedinfo.canonicalizationmethod(v=vs.110).aspx

您可能必须像这样创建自己的 Transform 类:

public class XmlDsigC14N11Transform: XmlDsigC14NTransform
    {
        public override void LoadInput(object obj)
        {
            //do something here
            base.LoadInput(obj);
        }

        public override object GetOutput()
        {
            //do something here
            return base.GetOutput();
        }
    }

并将您的转换映射到“http://www.w3.org/2006/12/xml-c14n11”。

CryptoConfig.AddAlgorithm(typeof(XmlDsigC14N11Transform), "http://www.w3.org/2006/12/xml-c14n11");

0
投票

这个问题有点老了,但这些天我偶然发现了它,发现第一个答案非常有用,尽管为了使其工作,我必须将规范化算法的命名空间添加到静态属性

SignedXml.KnownCanonicalizationMethods
。它是标准类的私有属性,但是通过一些技巧,您可以将命名空间添加到集合中,如下所示:

var KnownCanonicalizationMethodsProperty = typeof(SignedXml).GetProperty("KnownCanonicalizationMethods", BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Static);

(KnownCanonicalizationMethodsProperty.GetValue(null) as List<string>).Add("http://www.w3.org/2006/12/xml-c14n11");
© www.soinside.com 2019 - 2024. All rights reserved.