Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
PFX to PEM (Certificate and Private Key Files)Export a certificate and private key from a PFX to a pair of PEM files. import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { boolean success; CkCertStore certStore = new CkCertStore(); // Load the PFX file into a certificate store object String password; password = "myPassword"; success = certStore.LoadPfxFile("chilkat.pfx",password); if (success != true) { System.out.println(certStore.lastErrorText()); return; } // Find the cert to be exported by the subject: CkCert cert; cert = certStore.FindCertBySubject("Chilkat Software, Inc."); if (cert == null ) { System.out.println("Certificate not found."); return; } // Does this cert have a private key? if (cert.HasPrivateKey() == true) { // Get the private key. CkPrivateKey pvkey; pvkey = cert.ExportPrivateKey(); // Export the private key to a PEM file: success = pvkey.SaveRsaPemFile("chilkat_pkey.pem"); if (success != true) { System.out.println(pvkey.lastErrorText()); return; } } // Save the cert to a PEM file: success = cert.ExportCertPemFile("chilkat_cert.pem"); if (success != true) { System.out.println(cert.lastErrorText()); return; } } } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.