Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Email Object
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

PFX to PEM (Certificate and Private Key Files)

Export a certificate and private key from a PFX to a pair of PEM files.

Download Chilkat Java Library

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.