c# - C#中如何判断哪个个人证书来自硬件设备?

标签 c# x509certificate cryptoapi e-token

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

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

我应该为此使用 X509StoreX509Crtificate 吗?

我应该试用 eToken SDK 吗?

最佳答案

这可以帮助您找到证书。 它创建了一个位置和商店列表,并给出了证书的数量。 在输入和输出 token 的情况下运行它可以帮助您找到它的位置:

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

关于c# - C#中如何判断哪个个人证书来自硬件设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20648110/

相关文章:

c - 使用 cryptoapi CryptImportKey 导入公钥时出错

c# - 列 '[Group]' 不属于表表

heroku - x509 : certificate signed by unknown authority

Java 文件加密

java - 使用 PrivateKey、PublicKey 和 Certificate 对象设置 SSLContext

c# - 带可选 ClientCertificate 的 SslStream AuthenticateAsServer

c# - 使用 CryptoAPI 在 Store C# 中通过哈希查找证书

c# - 如何将var转换为DataTable?

c# - Web 服务仅适用于根文件夹

c# - WPF 将祖先对象绑定(bind)为 CommandParameter