PFX and P12 are one and the same. Both are PKCS #12 files (Personal Information Exchange Syntax). Both file extensions (.pfx and .p12) refer to files that contain PCKS #12 content.
Question:
I am trying to load a cert from file and am having difficulty on the Chilkat.Cert.LoadFromFile method. I am not sure if the issue is the file path given or permissions on the cert file.
Answer:
Use the LoadPfxFile method to load a .p12 or .pfx. Use LoadFromFile to load .cer, .crt, or PEM format certificates.
Note: Chilkat.Cert.LoadPfxFile should only be called if the .pfx contains a single certificate. Otherwise, you should call Chilkat.CertStore.LoadPfxFile to load the .pfx/.p12 into a certificate store object. You would then select your cert by calling a method such as FindCertBySubjectCN (to find by common name), FindCertBySubjectE (to find by email address), etc.
Incorrect Code:
// Load and set the encryption certificate
Chilkat.Cert cert = new Chilkat.Cert();
cert.LoadFromFile("certs\\publicWebsite.p12");
email.SetEncryptCert(cert);
Correct Code for .PFX containing a single certificate:
// Load and set the encryption certificate
Chilkat.Cert cert = new Chilkat.Cert();
cert.LoadPfxFile("certs\\publicWebsite.p12");
email.SetEncryptCert(cert);
Correct Code for .PFX containing multiple certificates:
Chilkat.CertStore certStore = new Chilkat.CertStore();
bool success = certStore.LoadPfxFile("certs\\publicWebsite.p12");
// You may wish to check the return value (true = success, false = failed)
Chilkat.Cert cert;
cert = certStore.FindCertBySubjectE("support@chilkatsoft.com");
// Check for a null return...
email.SetEncryptCert(cert);