Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Export Certificate and Private Key to PFXDemonstrates how to export a digital certificate, it's private key, and potentially all certificates in the chain of authentication to a PFX file. Downloads for Windows/Linux and Install Instructions require 'rubygems' require 'chilkat' # This object is used to create a certificate store object. ccs = Chilkat::CkCreateCS.new() # 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 == nil ) # Open the current-user certificate store and check it instead. print "Checking current-user certificate store..." + "\n"; certStore = ccs.OpenCurrentUserStore() cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com") if (cert == nil ) print "Failed to find certificate!" + "\n"; exit end end # 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() + "\n"; else print "Exported to PFX!" + "\n"; end else print "Certificate does not have a private key available" + "\n"; end # 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.