Hi Peter,
As you said that you want some information about verifying X509 certificate
signature, I'd like to confirm what's the exact verification you want.
My understanding is that you may have a X509 certificate which assocate
with a publickey/private key pair( of RSA or DSA encypt provider) and
you've also used the private key to digital signed some data, and want to
verify the data, correct?
If this is the case, generally you will need to do two things here:
1. Retrieve the public/private key from the certificate (in certificate
store of windows)
2. use the key info associated with the certificate to do encryption or
digital sign.
Here are some web articles introducing some code on this:
http://www.codeproject.com/KB/security/RSACryptoPad.aspx
http://www.eggheadcafe.com/articles/20020630.asp
and here is a simple test function I've written which include accessing
cert store to retrieve key info in cert and do some RSA signing and
verification:
======================================
private void btnTest_Click(object sender, EventArgs e)
{
RSACryptoServiceProvider rsa;
RSAParameters key;
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
bool result;
signSrc = Encoding.UTF8.GetBytes("ABCDEFG");
string tp = "2b6f8ac51a85cbaf429474a55304313968667611";
X509Store store = new X509Store(StoreName.My,
StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert2 =
store.Certificates.Find(X509FindType.FindByThumbprint, tp, true)[0];
store.Close();
rsa = cert2.PrivateKey as RSACryptoServiceProvider;
signDes = rsa.SignData(signSrc, sha);
result = rsa.VerifyData(signSrc, sha, signDes);
MessageBox.Show("valid: " + result);
/** here try exporting the CERT to a exportable file */
byte[] pfx_bytes =
cert2.Export(X509ContentType.Pfx,"Password01!");
//txtContent.Text = Convert.ToBase64String(pfx_bytes);
X509Certificate2 filecert = new X509Certificate2();
filecert.Import(pfx_bytes, "Password01!",
X509KeyStorageFlags.DefaultKeySet);
RSACryptoServiceProvider rsa1 = filecert.PrivateKey as
RSACryptoServiceProvider;
result = rsa1.VerifyData(signSrc, sha, signDes);
MessageBox.Show("valid: " + result);
string expkey = Convert.ToBase64String(rsa.ExportCspBlob(true));
txtExportedKey.Text = expkey;
}
=================================================
Hope this helps some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=
Subject: Verifying X509Certificate signature
Date: Wed, 30 Jul 2008 18:23:00 -0700
Sorry for the cross-post; the last post didn't use the correct MSDN e-mail...
Can anyone point me in the right direction for verifying an X509Certificates
signature? i.e. that it was truly signed by a known/trusted certificate
Thanks -- Peter