Add X509 certificate to storage in code

This code will add the x509 cer certificate file to the certificate store (using System.Security.Cryptography.X509Certificates ):

  var filename = "Cert.cer"; var cert = new X509Certificate2(filename); var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(cert); 

If the certificate is generated using:

 makecert -r -pe -sky exchange -n "CN=Blah" Cert.cer -sv Cert.pvk 

But - this will add the certificate in the "Personal" certificates in CurrentUser - how can I add the certificate to another collection of certificates - in my case, I want to add certificates for CurrentUser to the "Trusted People".

thanks

+4
source share
1 answer
 var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser); 

The first parameter contains the enumeration for which the storage is used, see MSDN

The second parameter contains an enumeration for the use of which (for example, computer, current user) see MSDN

+8
source

All Articles