Python Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Python Examples

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

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

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Export Certificate and Private Key to PFX

Demonstrates how to export a digital certificate, it's private key, and potentially all certificates in the chain of authentication to a PFX file.

Download Chilkat Python Library

import sys
import chilkat



#  This object is used to create a certificate store object.
ccs = chilkat.CkCreateCS()

#  Open the local machine certificate store read-only.
ccs.put_ReadOnly(True)
certStore = ccs.OpenLocalSystemStore()

#  Can we find a certificate by email address?

cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com")
if (cert == None ):
    #  Open the current-user certificate store and check it instead.

    print "Checking current-user certificate store..."

    certStore = ccs.OpenCurrentUserStore()

    cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com")
    if (cert == None ):
        print "Failed to find certificate!"
        sys.exit()

#  Does this certificate have a private key accessible
#  to the calling process?  Private keys are *not* stored
#  within the certificate store.  Private keys are stored
#  in a key container in a Windows protected store.  It
#  can be one of two protected stores: the protected store for
#  the current logged-in user account, or the "machine-key"
#  protected store.  The private key must both exist in a
#  protected store, and the process must have permission to
#  access it...

#  You can only export to a PFX if the private key exists
#  and is accessible.

if (cert.HasPrivateKey() == True):

    #  Export to a PFX.
    #  Provide a password that will be required whenever the PFX is opened.
    #  Also, include all certs in the chain of authentication.

    bIncludeChain = True
    success = cert.ExportToPfxFile("myCert.pfx","myPassword",bIncludeChain)
    if (success != True):
        print cert.lastErrorText()
    else:
        print "Exported to PFX!"

else:
    print "Certificate does not have a private key available"

#  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.

 

Need a specific example? Send a request to support@chilkatsoft.com

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