var store = new X509Store(StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, "thumbprint", false); var cert = certificates[0]; store.Close();
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); var cert = new X509Certificate2("certificate.cer"); store.Add(cert); store.Close();This code opens the LocalMachine personal (My) certificate store for both reading and writing, adds a new certificate to the store, and then closes the store. The System.Security.Cryptography.X509Certificates namespace is part of the .NET Framework Class Library.