Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

December 27, 2007

.pfx = .p12

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);


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.