Home > Uncategorized > Verify #SSL expiry using C#

Verify #SSL expiry using C#


Need to remember when to renew a SSL cert?, here’s some handy code in c#

using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;

namespace CheckSSL
class Program
static void Main(string[] args)
//Do webrequest to get info on secure site
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“https://www.avatarapi.com”);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//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();



Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: