Skip to content

Instantly share code, notes, and snippets.

@code-atom
Created January 6, 2017 04:33
Show Gist options
  • Save code-atom/e20657e8a398fd0dd679d1731e6200ba to your computer and use it in GitHub Desktop.
Save code-atom/e20657e8a398fd0dd679d1731e6200ba to your computer and use it in GitHub Desktop.
Check when SSL get expire.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mail.google.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
//retrieve the ssl cert and assign it to an X509Certificate object
X509Certificate cert = request.ServicePoint.Certificate;
//convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
X509Certificate2 cert2 = new X509Certificate2(cert);
string cn = cert2.GetIssuerName();
string cedate = cert2.GetExpirationDateString();
string cpub = cert2.GetPublicKeyString();
Console.WriteLine(cert2.GetExpirationDateString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment