Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Export certificates and public/private keys from a PFXDemonstrates how to export certificates and public/private keys from a PFX file. LOCAL lnSuccess LOCAL loCertStore LOCAL lcPassword LOCAL i LOCAL lnNumCerts LOCAL loCert LOCAL lcFname LOCAL loPvkey LOCAL loPubkey loCertStore = CreateObject('Chilkat.CertStore') * Load the PFX file into a certificate store object lcPassword = "myPassword" lnSuccess = loCertStore.LoadPfxFile("chilkat.pfx",lcPassword) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCertStore.LastErrorText) QUIT ENDIF lnNumCerts = loCertStore.NumCertificates FOR i = 0 TO lnNumCerts - 1 loCert = loCertStore.GetCertificate(i) ? loCert.SubjectDN ? "---" * Save the cert in DER format: lcFname = "cert" + STR(i) + ".der" loCert.ExportCertDerFile(lcFname) * Save the cert in PEM format: lcFname = "cert" + STR(i) + ".pem" loCert.ExportCertPemFile(lcFname) * Does this cert have a private key? IF (loCert.HasPrivateKey() = 1) THEN * Get the private key. loPvkey = loCert.ExportPrivateKey() * Save the private key to a PKCS8 DER-encoded file lcFname = "pvkey" + STR(i) + "_pkcs8.der" loPvkey.SavePkcs8File(lcFname) * Save the private key to a PKCS8 PEM-encoded file lcFname = "pvkey" + STR(i) + "_pkcs8.pem" loPvkey.SavePkcs8PemFile(lcFname) * Save the private key to a RSA DER-encoded file lcFname = "pvkey" + STR(i) + "_rsa.der" loPvkey.SaveRsaDerFile(lcFname) * Save the private key to a RSA PEM-encoded file lcFname = "pvkey" + STR(i) + "_rsa.pem" loPvkey.SaveRsaPemFile(lcFname) * 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. lcFname = "pvkey" + STR(i) + ".xml" loPvkey.SaveXmlFile(lcFname) RELEASE loPvkey ENDIF * Now get the public key and save it to various file formats: loPubkey = loCert.ExportPublicKey() * Save to an OpenSSL DER format file: lcFname = "pubkey" + STR(i) + "_openSsl.der" loPubkey.SaveOpenSslDerFile(lcFname) * Save to an OpenSSL PEM format file: lcFname = "pubkey" + STR(i) + "_openSsl.pem" loPubkey.SaveOpenSslPemFile(lcFname) * Save to an RSA DER format file: lcFname = "pubkey" + STR(i) + "_rsa.der" loPubkey.SaveRsaDerFile(lcFname) * Save to an XML file: * This format is Chilkat-specific, but easily parsed, * making it easy to get the modulus and exponent. lcFname = "pubkey" + STR(i) + ".xml" loPubkey.SaveXmlFile(lcFname) RELEASE loPubkey RELEASE loCert NEXT * 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-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser