Reputation: 75093
I have made a simple console app that loops through all the Certificates on a Machine
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;
}
using StoreName.CertificateAuthority
and StoreLocation.LocalMachine
as the variables, on my Windows Server 2008R2, I only get 3 Certificates even though there are many more installed
console app output:
installed certificates under the CertificateAuthority
store location
How do I get the missing ones?
I specially wan to retrieve the Apple Certificate one to sign files, but no matter how I install the public certificate, I can not retrieve it from a store loop...
Do I always need to restart the machine? Is there a special trick to get them?
Upvotes: 1
Views: 677
Reputation: 63203
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,
Upvotes: 1
Reputation: 2369
Generally, it should work with loading the "CertificateAuthority" store and fetching it from there, so it's kinda weird.
However, according to MSDN: http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename.aspx
It should be possible to load the Apple certificate like this:
var appleCert = new X509Certificate2("appleRoot.cer");
Just to get you started.
Upvotes: 0