Installing Certificate using C#
-
Hi, I am trying to install a .pfx certificate in personal folder using a C# application. Every thing goes fine and certificate is installed. I can see that certificate in the Personal folder of both Current User and Local machine. But when i try to run my application and use that certificate, it throws exception with the message: The credentials supplied to the package were not recognized Stack Trac at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String package, CredentialUse intent, SecureCredential scc)...... But when i import this cert manually, it works just fine. Below is the code i am using for installing the certificate:
Dim cert_personal As X509Certificate2 = Nothing Try cert_personal = New X509Certificate2 cert_personal.Import(Application.StartupPath & "\Chain\Personal.pfx","My Password" , (X509KeyStorageFlags.UserKeySet Or X509KeyStorageFlags.Exportable)) Catch ex As Exception MsgBox(ex.Message) End Try If cert_personal Is Nothing Then Return False End If ''XXXXXXXXXXXXXXXXXXXXXXXX PERSONAL XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Dim store As New X509Store(StoreName.My, StoreLocation.CurrentUser) Try store.Open(OpenFlags.ReadWrite) Dim findVal As String = cert_personal.Thumbprint 'Thumbprint Dim certColl As X509Certificate2Collection = store.Certificates.Find(X509FindType.FindByThumbprint, findVal, False) If certColl.Count <= 0 Then store.Add(cert_personal) End If Catch ex As Exception MsgBox(ex.Message) Finally store.Close() End Try
And almost same for installing in Local machine. The complete chain is also fine. But the problem is still there. I can't use CertMgr since this cert is from a third party which is not , as per my info, supported by that. Any suggestion, code sample, advice would be highly appreciated. Thanks in advance, Wasif Ehsan.