(VB.NET) Import a Certificate (.cer file) into a Windows Certificate Store
Demonstrates how to import a certificate (without private key) into a Windows certificate store.
Dim cert As New Chilkat.Cert
Dim success As Boolean = cert.LoadFromFile("qa_data/certs/example.cer")
If (success = False) Then
Debug.WriteLine(cert.LastErrorText)
Exit Sub
End If
Dim certStoreCU As New Chilkat.CertStore
Dim readOnlyFlag As Boolean = False
' "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
success = certStoreCU.OpenWindowsStore("CurrentUser","My",readOnlyFlag)
If (success = False) Then
Debug.WriteLine("Failed to open the CurrentUser/My certificate store for read/write.")
Exit Sub
End If
' Import the certificate into the CurrentUser/My certificate store.
success = certStoreCU.AddCertificate(cert)
If (success = False) Then
Debug.WriteLine(certStoreCU.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Imported " & cert.SubjectCN)
Debug.WriteLine("Success.")
|