HTTPS and X509 certificates in .NET Part 4: working with certificates in code
June 8, 2015 11 Comments
Introduction
In the previous post we successfully installed our self-signed CA certificate in the Trusted Root CA folder. We also installed a derived certificate in the Personal certificates folder. We then saw how to make IIS use our certificate for a secured web site.
In this post we’ll start looking into the certificate-related classes in .NET.
Loading a certificate from a file
Digital certificates are represented by the X509Certificate2 class in .NET located in the System.Security.Cryptography.X509Certificates namespace. The class has numerous overloaded constructors. You can pass in the file path to the certificate, a byte array content, a password etc. Let’s see whether we can load the CA certificate we created before in this series: