簡體   English   中英

如何通過C#代碼獲取中間證書和受信任的根證書的到期日期?

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

如何通過C#代碼獲取中間證書和受信任的根證書的到期日期?

我需要在Internet Option(->內容->證書)中獲取有關證書的數據。

使用X509Certificate.GetExpirationDateString方法

要獲取證書,請使用:

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

我沒有包括異常處理和檢查是否清晰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM