在 C# 中,使用 x.509 证书签署 xml 并检查签名
我正在尝试使用 x.509 证书对 XML 文件进行签名,我可以使用私钥对文档进行签名,然后使用 CheckSignature 方法(它具有接收证书作为参数的重载)来验证签名。
问题是验证签名的用户必须拥有证书,我担心的是,如果用户拥有证书,那么他就可以访问私钥,据我了解,这是私有的,应该仅对用户可用谁签名。
我缺少什么?
感谢您的帮助。
I'm trying to sign an XML file using a x.509 certificate, I can use the private key to sign the document and then use the CheckSignature method (it has an overload that receives a certificate as parameter) to verify the signature.
The problem is that the user who validates the signature must have the certificate, my concern is, if the user has the certificate then he has access to the private key, and as I understand, this is private and should be available only to the user who signs.
What am I missing?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 .NET 中,如果您从 .pfx 文件获取 X509 证书,如下所示:
那么您可以像这样导出公钥部分:
“false”部分表示,仅导出公共部分,不导出私有部分。 (RSA.ToXmlString 的文档)
然后在验证应用程序中,使用
VerifyXml 调用
CheckSignature()
。 它看起来像这样:In .NET, If you get your X509 cert from a .pfx file, like this:
Then you can export the public key portion like so:
The "false" part says, only export the public piece, don't export the private piece. (doc for RSA.ToXmlString)
And then in the verifying application, use
And the VerifyXml calls
CheckSignature()
. It looks something like this:任何证书都有公共部分和私有部分。 您只发送公共部分。 只需在浏览器中打开任何启用 SSL 的网站,单击挂锁符号即可查看其证书。
Any certificate has a public and a private part. You only send around the public part. Just open any SSL enabled website in your browser, click on the padlock symbol and have a look at their certificate.
首先,您需要确保证书是 .pfx 或 .cer
您正在使用的旨在用于签名目的。
此处编写了用于用 C# 对 XmlDocument 进行数字签名/验证的完整控制台应用程序。
First off all you need to be sure that the certificate .pfx or .cer
that you are using is intended for signing purpose.
A Complete console application to digitally sign/verify XmlDocument in C# is written here.