2015-11-24 22 views
2

我已經在我的電腦上安裝了一個證書,並且正在嘗試讀取容器名稱屬性。這是可能的和如何?閱讀客戶端證書容器名稱

public void Read() 
    { 
     X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); 

     store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); 

     foreach (X509Certificate2 mCert in store.Certificates) 
     { 
      //Find Container name? 
     } 
    } 

回答

2

在這裏,你去。

public static void Read() 
{ 
    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); 

    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); 

    foreach (X509Certificate2 mCert in store.Certificates) 
    { 
     //Find Container name? 

     var privateKey = mCert.PrivateKey as RSACryptoServiceProvider; 

     var uniqueKeyContainerName = privateKey.CspKeyContainerInfo.UniqueKeyContainerName; 
     var keyContainerName = privateKey.CspKeyContainerInfo.KeyContainerName; 
     var ProviderName = privateKey.CspKeyContainerInfo.ProviderName; 
     // etc. 
    } 
} 

更多信息有關CspKeyContainerInfohere

+0

我已經在我的證書上設置了一個自定義私有容器名稱,但它現在看起來已加密(或者我無法找到它)。它是否會像那樣工作,或者我怎樣才能解密它? – MrProgram

+0

@emptyman你能解釋一下嗎?我不明白你在做什麼。恕我直言,我正確回答了你以前的問題。 – pepo