How can I get the expiration date of an intermediate certificate and trusted root certificate by C# code?
How can I get the expiration date of an intermediate certificate and trusted root certificate by C# code?
I need to get data abo开发者_运维问答ut a certificate in Internet Option (-> content -> certificates).
Use the X509Certificate.GetExpirationDateString Method.
To get the certificate, use:
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(
X509FindType.FindBySubjectDistinguishedName,
"name",
false);
X509Certificate2 cert = certs[0];
cert.GetExpirationDateString();
I have not included exception handling and checks for clarity.
精彩评论