3

假设我有当前用户的多个个人证书。但只有一张证书属于阿拉丁 eToken。

我想确定哪个证书属于 Aladdin eToken。

我应该使用X509StoreandX509Crtificate吗?

我应该尝试 eToken SDK 吗?

4

2 回答 2

0

这可以帮助您找到证书。它创建一个位置和商店列表,并给出证书的数量。使用令牌和令牌运行它可以帮助您找到它在哪里:

public static string ListCertificatesCount()
{
    string output = "";
    foreach (StoreName st in (StoreName[])Enum.GetValues(typeof(StoreName)))
    {
        foreach (StoreLocation loc in (StoreLocation[])Enum.GetValues(typeof(StoreLocation)))
        {
            string line = "StoreName " + Enum.GetName(typeof(StoreName), st) + ", StoreLocation " + Enum.GetName(typeof(StoreLocation), loc) + ": Count: ";
            try
            {
                using (X509Store keyStore = new X509Store(st, loc))
                {
                    keyStore.Open(OpenFlags.ReadOnly);
                    line += keyStore.Certificates.Count;
                    keyStore.Close();
                }
            }
            catch (Exception ex)
            {
                line += "Fail: " + ex.Message;
            }
            output += line + Environment.NewLine;
        }
    }
    return output;
}
于 2020-07-02T07:27:29.160 回答
-1

这取决于阿拉丁 eToken 如何签署证书。如果它颁发的 X509 证书的颁发者字段设置为可识别的内容(例如,Aladdin eToken),那么您应该能够以这种方式找到证书。

// Get the MY store for the current user
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

store.Open(OpenFlags.ReadOnly);

X509Certificate2Collection certs = 
    store.Certificates.Find(X509FindType.FindByIssuerName,
                            "Aladdin eToken");

这应该会为您提供所有在发行者名称中具有字符串“Aladdin eToken”的证书。如果您需要使用不同的标准来识别证书,还有大量其他有效参数,您可以传递集合的Find方法Certificates来获取匹配项。

例如,如果您要查找特定证书,您可以FindByThumbprintFindBySerialNumber.

于 2013-12-18T02:21:05.753 回答