Perl Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Perl Examples

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

More Examples...
String
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Export certificates and public/private keys from a PFX

Demonstrates how to export certificates and public/private keys from a PFX file.

 Chilkat Perl Module Downloads for Windows, Linux, and MAC OS X

use chilkat();


$certStore = new chilkat::CkCertStore();

#  Load the PFX file into a certificate store object

$password = "myPassword";
$success = $certStore->LoadPfxFile("chilkat.pfx",$password);
if ($success != 1) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

$numCerts = $certStore->get_NumCertificates();

for ($i = 0; $i <= $numCerts - 1; $i++) {

    $cert = $certStore->GetCertificate($i);

    print $cert->subjectDN() . "\r\n";
    print "---" . "\r\n";

    #  Save the cert in DER format:
    $fname = "cert" . $i . ".der";
    $cert->ExportCertDerFile($fname);

    #  Save the cert in PEM format:
    $fname = "cert" . $i . ".pem";
    $cert->ExportCertPemFile($fname);

    #  Does this cert have a private key?
    if ($cert->HasPrivateKey() == 1) {

        #  Get the private key.

        $pvkey = $cert->ExportPrivateKey();

        #  Save the private key to a PKCS8 DER-encoded file
        $fname = "pvkey" . $i . "_pkcs8.der";
        $pvkey->SavePkcs8File($fname);

        #  Save the private key to a PKCS8 PEM-encoded file
        $fname = "pvkey" . $i . "_pkcs8.pem";
        $pvkey->SavePkcs8PemFile($fname);

        #  Save the private key to a RSA DER-encoded file
        $fname = "pvkey" . $i . "_rsa.der";
        $pvkey->SaveRsaDerFile($fname);

        #  Save the private key to a RSA PEM-encoded file
        $fname = "pvkey" . $i . "_rsa.pem";
        $pvkey->SaveRsaPemFile($fname);

        #  Save the private key to an XML file
        #  This format is Chilkat-specific, but easily parsed,
        #  making it easy to get the modulus, exponent,
        #  P, Q, DP, DQ, InverseQ, and D.
        $fname = "pvkey" . $i . ".xml";
        $pvkey->SaveXmlFile($fname);

    }

    #  Now get the public key and save it to various file formats:

    $pubkey = $cert->ExportPublicKey();

    #  Save to an OpenSSL DER format file:
    $fname = "pubkey" . $i . "_openSsl.der";
    $pubkey->SaveOpenSslDerFile($fname);

    #  Save to an OpenSSL PEM format file:
    $fname = "pubkey" . $i . "_openSsl.pem";
    $pubkey->SaveOpenSslPemFile($fname);

    #  Save to an RSA DER format file:
    $fname = "pubkey" . $i . "_rsa.der";
    $pubkey->SaveRsaDerFile($fname);

    #  Save to an XML file:
    #  This format is Chilkat-specific, but easily parsed,
    #  making it easy to get the modulus and exponent.
    $fname = "pubkey" . $i . ".xml";
    $pubkey->SaveXmlFile($fname);

}

#  The Chilkat Certificate, Certificate Store, Private Key,
#  Public Key, and Key Container classes / objects are freeware.

#  They are used by and included with the Chilkat Email,
#  Crypt, S/MIME, and other commercial Chilkat components.

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.