
我的问题是,我似乎无法生成有效的签名.第三方服务和我找到的在线签名验证器都将签名报告为无效.验证服务(http://www.aleksey.com/xmlsec/xmldsig-verifier.html)报告摘要和数据之间存在不匹配,到目前为止我还无法弄清楚我做错了什么.
这是相关的代码 – 希望有人能够发现我的错误;
public static Xdocument Signdocument(Xdocument originaldocument,X509Certificate2 certificate){ var document = new Xmldocument(); document.LoadXml(originaldocument.ToString(SaveOptions.disableFormatting)); if (document.documentElement == null) throw new InvalIDOperationException("InvalID XML document; no root element found."); var signeddocument = new SignedXml(document); Reference signatureReference = GetSignatureReference(); KeyInfo certificateKeyInfo = GetCertificateKeyInfo(certificate); var dataObject = new DataObject("","text/xml","utf-8",document.documentElement); signeddocument.AddReference(signatureReference); signeddocument.Addobject(dataObject); signeddocument.SigningKey = certificate.PrivateKey; signeddocument.KeyInfo = certificateKeyInfo; signeddocument.ComputeSignature(); return Xdocument.Parse(signeddocument.GetXml().OuterXml,LoadOptions.PreserveWhitespace);}private static Reference GetSignatureReference(){ var signatureReference = new Reference(""); signatureReference.Addtransform(new XmlDsigEnvelopedSignaturetransform()); return signatureReference;}private static KeyInfo GetCertificateKeyInfo(X509Certificate certificate){ var certificateKeyInfo = new KeyInfo(); certificateKeyInfo.AddClause(new KeyInfoX509Data(certificate)); return certificateKeyInfo;}解决方法 如果有人有兴趣,我解决了这个问题并在我的博客上写了这篇文章: http://thomasjo.com/blog/2009/08/04/xmldsig-in-the-net-framework.html 总结
以上是内存溢出为你收集整理的c# – SignedXml生成无效签名全部内容,希望文章能够帮你解决c# – SignedXml生成无效签名所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)