Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) Get Public Key from CSRDemonstrates how to get the public key from a CSR.
LOCAL loPem LOCAL lcNoPassword LOCAL lnSuccess LOCAL lcStrBase64 LOCAL loAsn LOCAL loXml LOCAL lcStrModulusHex LOCAL loBd LOCAL lcModulus64 LOCAL loXmlPubKey LOCAL loPubkey LOCAL lnPreferPkcs1 * This requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Pem') loPem = CreateObject('Chilkat.Pem') * No password is required. Pass an empty password string.. lcNoPassword = "" lnSuccess = loPem.LoadPemFile("qa_data/csr/csr2.pem",lcNoPassword) IF (lnSuccess <> 1) THEN ? loPem.LastErrorText RELEASE loPem CANCEL ENDIF lcStrBase64 = loPem.GetEncodedItem("csr","","base64",0) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Asn') loAsn = CreateObject('Chilkat.Asn') lnSuccess = loAsn.LoadEncoded(lcStrBase64,"base64") IF (lnSuccess <> 1) THEN ? loAsn.LastErrorText RELEASE loPem RELEASE loAsn CANCEL ENDIF * Convert the ASN.1 to XML. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') lnSuccess = loXml.LoadXml(loAsn.AsnToXml()) ? loXml.GetXml() ? "----" lcStrModulusHex = loXml.GetChildContent("bits") ? "strModulusHex = " + lcStrModulusHex ? "----" * We need the modulus as base64. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData') loBd = CreateObject('Chilkat.BinData') loBd.AppendEncoded(lcStrModulusHex,"hex") lcModulus64 = loBd.GetEncoded("base64") ? "modulus64 = " + lcModulus64 ? "----" * Build the XML for the public key. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXmlPubKey = CreateObject('Chilkat.Xml') loXmlPubKey.Tag = "RSAPublicKey" loXmlPubKey.UpdateChildContent("Modulus",lcModulus64) * The RSA exponent will always be decimal 65537 (base64 = AQAB) loXmlPubKey.UpdateChildContent("Exponent","AQAB") ? "RSA public key as XML:" ? loXmlPubKey.GetXml() ? "----" * Load the XML into a Chilkat public key object. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.PublicKey') loPubkey = CreateObject('Chilkat.PublicKey') lnSuccess = loPubkey.LoadFromString(loXmlPubKey.GetXml()) IF (lnSuccess <> 1) THEN ? loPubkey.LastErrorText RELEASE loPem RELEASE loAsn RELEASE loXml RELEASE loBd RELEASE loXmlPubKey RELEASE loPubkey CANCEL ENDIF * Show the public key as PEM. lnPreferPkcs1 = 1 ? loPubkey.GetPem(lnPreferPkcs1) RELEASE loPem RELEASE loAsn RELEASE loXml RELEASE loBd RELEASE loXmlPubKey RELEASE loPubkey |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.