Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add a certificate to the windows certificate store?

I tried the below code. But the certificate is not getting added to the certificate store.
Code:
C#
string certificateFilePath=@"C:\Documents and Settings\alexander.junior\Desktop\Test.cer";
// Convert the Filename to an X509 Certificate
 X509Certificate2 cert = new X509Certificate2(certificateFilePath);

// Get the server certificate store
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

store.Open(OpenFlags.MaxAllowed);
store.Add(cert); // x509 certificate created from a user supplied filename
Posted
Updated 27-Oct-15 12:06pm
v2
Comments
saddam abu ghaida 27-Oct-15 18:14pm    
what is the error that you are getting or it just doesn't add the cert ?

1 solution

hello I think this should work

C#
X509Store store = new X509Store(StoreName.My, StoreLocation. LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(certificateFilePath)));
store.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900