using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; namespace Add_certificate_in_local_store_in_Csharp { class Program { static void Main(string[] args) { string certraw = @"-----BEGIN CERTIFICATE----- MIIEyjCCA7KgAwIBAgICJ74wDQYJKoZIhvcNAQELBQAwOjELMAkGA1UEBhMCSU4x EjAQBgNVBAoTCUluZGlhIFBLSTEXMBUGA1UEAxMOQ0NBIEluZGlhIDIwMTQwHhcN MTYwNTEyMTAwMzA1WhcNMjQwMzA1MDYzMDAwWjCB4jELMAkGA1UEBhMCSU4xLTAr BgNVBAoTJENhcHJpY29ybiBJZGVudGl0eSBTZXJ2aWNlcyBQdnQgTHRkLjEdMBsG A1UECxMUQ2VydGlmeWluZyBBdXRob3JpdHkxDzANBgNVBBETBjExMDA5MjEOMAwG A1UECBMFREVMSEkxJzAlBgNVBAkTHjE4LExBWE1JIE5BR0FSIERJU1RSSUNUIENF TlRFUjEfMB0GA1UEMxMWRzUsVklLQVMgREVFUCBCVUlMRElORzEaMBgGA1UEAxMR Q2Fwcmljb3JuIENBIDIwMTQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB AQDTeRm/NQgUluYeSKyKb+ahHHl/MqdPXsFs/uoSF9B+fiwpfeFBUIUNNEw62BJa Wjs2gwT9SnZBPLORXRFBUy/yv0s5eXcIpL/47/Sq8gfUQbVuBVCmu4oY2Sbigd8q i+Y/IhLHbpuaCugkSxQYvb6dfBR81PwSD6WaGpTFDyiJEhWPlEpzQaKTaJFVl45R /hykwl1CY7nwjU+VklaMwWyNqOxDVHNv3I8c0BXKIDMKx7PghKhEL8kbRzu1Uzi1 te6iYJSsREFHGztz0I6OGvX5Ngc1wsx5sZQyxsqTeVgN1w+1cDI046DLKlG0kcx/ CnC/d6lNuz9xe2+3A3GIgiFzAgMBAAGjggEvMIIBKzATBgNVHSMEDDAKgAhCuMXP bbNX4TCBgAYIKwYBBQUHAQEEdDByMB4GCCsGAQUFBzABhhJodHRwOi8vb2N2cy5n b3YuaW4wUAYIKwYBBQUHMAKGRGh0dHA6Ly93d3cuY2NhLmdvdi5pbi9jY2Evc2l0 ZXMvZGVmYXVsdC9maWxlcy9maWxlcy9DQ0FJbmRpYTIwMTQuY2VyMBIGA1UdIAQL MAkwBwYFYIJkZAIwRgYDVR0fBD8wPTA7oDmgN4Y1aHR0cDovL2NjYS5nb3YuaW4v cncvcmVzb3VyY2VzL0NDQUluZGlhMjAxNExhdGVzdC5jcmwwEQYDVR0OBAoECEOA BKAHteDPMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAGAQH/AgEAMA0GCSqG SIb3DQEBCwUAA4IBAQBYGjeeabZFUG68NGu+0fMETRzc0tfG/1tvIJVvK5ZCQx9U n2EXcATCD+icHkklKwBR+VeNQbtYrreMWP97tJqLuz4n/KCv57GRw8l55ktxkqFQ Ll7Z1r3rPl1moWHXkuW454cKRVVdjQ/BIfKr5gx3a5zLbYp7XcWIb88vAVD/LKc1 LCStIk7h54/VClBiBmeXze5RkBB2awzu6W2sU7l53oxUoTSatafMM5n5HKxGvLvA cCPU7XCr10v4hEZp4TwPJ8kZOddNSUbHeL8gftpgJvLlzNI4nXppSQzzdQtTJpdL 7CRwd735/i6I6hOxGAI1WSutzTcR9pHjvLadOXCj -----END CERTIFICATE----- "; X509Certificate2 cert = new X509Certificate2(); cert.Import(System.Text.UTF8Encoding.ASCII.GetBytes(certraw)); X509Store store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); Console.WriteLine("We are now installing the CA certificate into the Trusted Root Certificate store ..."); store.Add(cert); Console.WriteLine("Done! The CA certificate was successfully. Press any key to close."); Console.ReadKey(); store.Close(); } } }