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.
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: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.
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.