开发者

How can I get the expiration date of an intermediate certificate and trusted root certificate by C# code?

开发者 https://www.devze.com 2023-01-06 15:48 出处:网络
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消