views:

4296

answers:

2

I have a certificate generated via MakeCert. I want to use this certificate for WCF message security using PeerTrust. How can I programmatically install the certificate into the "trusted people" local machine certificate store using c# or .NET?

I have a CER file, but can also create a PFX.

+4  A: 

I believe that this is correct:

X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
store.Add(cert); //where cert is an X509Certificate object
Demi
+4  A: 

The following works good for me:

private static void InstallCertificate(string cerFileName)
{
    X509Certificate2 certificate = new X509Certificate2(cerFileName);
    X509Store store = new X509Store(StoreName.TrustedPublisher, StoreLocation.LocalMachine);

    store.Open(OpenFlags.ReadWrite);
    store.Add(certificate);
    store.Close();
}