1

我制作了一个简单的控制台应用程序,它遍历机器上的所有证书

private static X509Certificate2 GetSpecifiedCertificate(StoreName storeName, StoreLocation storeLocation)
{
    X509Store store = new X509Store(storeName, storeLocation);
    store.Open(OpenFlags.ReadOnly);

    X509Certificate2Collection certs = store.Certificates;


    if (certs.Count > 0)
    {
        Console.WriteLine(string.Format("found {0} certficates", certs.Count));

        for (int i = 0; i < certs.Count; i++)
        {
            X509Certificate2 cert = certs[i];
            Console.WriteLine(cert.Thumbprint);
        }
    }
    else
        Console.WriteLine("found no certficates at all");

    return null;
}

使用StoreName.CertificateAuthorityandStoreLocation.LocalMachine作为变量,在我的 Windows Server 2008R2 上,即使安装了更多证书,我也只能获得 3 个证书

控制台应用程序输出: 在此处输入图像描述

CertificateAuthority在商店位置 下安装证书在此处输入图像描述

如何获得丢失的?

我特别想检索Apple证书来签署文件,但无论我如何安装公共证书,我都无法从商店循环中检索它......

我总是需要重新启动机器吗?有什么特殊的技巧可以得到它们吗?

4

2 回答 2

1

How did you open the certificate window? I think you are looking at the certificates under your account instead of the computer account. However, the code queries certificates from the computer account, which usually has less certificates installed than your account.

To open the certificates window for the computer account,

  1. Execute mmc at command prompt.
  2. File | Add/Remove Snap-in.
  3. Add Certificates.
  4. Choose Computer account.
于 2012-10-05T13:19:37.257 回答
0

通常,它应该与加载“CertificateAuthority”存储并从那里获取它一起工作,所以这有点奇怪。

但是,根据 MSDN:http: //msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename.aspx

应该可以像这样加载 Apple 证书:

var appleCert = new  X509Certificate2("appleRoot.cer");

只是为了让你开始。

于 2012-10-05T13:01:26.407 回答