读取客户端证书容器名称

时间:2015-11-24 14:53:58

标签: c# certificate

我在计算机上安装了证书,我正在尝试读取容器名称属性。这可能吗?怎么样?

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?
        }
    }

1 个答案:

答案 0 :(得分: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.
    }
}

有关CspKeyContainerInfo here的更多信息。