What is the difference between the two?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Mechanize getting “Errno::ECONNRESET: Connection r
- Bulk update SQL Server C#
The x509Certificate was introduced in .NET v1.0/1.1 and was (comparatively) limited in its functionality. It can be used to get information about an existing certificate (valid dates, issuer, etc.). It had simple methods/operations (i.e. reading a cert from disk).
The x509Certificate2 is a subclass of x509Certificate with additional functionality.
To convert an X.509 cert from "X509Certificate" to "X509Certificate2", try something like this:
For completeness' sake, here is a copy of the relevant section of the site linked to in @dommer's answer, since the site may no longer be up and only in Google's cache for who-knows-how long:
For those that would like to read the certificate and use this to authenticate one would simply create a X509Certificate2 and pass the X509Certificate in it's constructor.
For a signed assembly (the exe) the code would be code like this, and I omit error validation for simplicity.
Obviously you're class isn't called MyClass but some business object that you'd expect from the web service.
You can send a class to your action by sending the property & value you require filled. You can now ensure that the request you received is from a valid mobile or windows client by reading the request certificate like so:
}
What is left is to set your webserver to accept client certificates... You can read all about properties that come from the new format and you have secured your public web service, something most fail to do as just being authorized isn't good enough anymore (if it ever was)