Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) Get Public Key from CSRDemonstrates how to get the public key from a CSR.
// This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loPem = createobject("CkPem") // No password is required. Pass an empty password string.. lcNoPassword = "" llSuccess = loPem.LoadPemFile("qa_data/csr/csr2.pem",lcNoPassword) if (llSuccess <> .T.) then ? loPem.LastErrorText release loPem return endif lcStrBase64 = loPem.GetEncodedItem("csr","","base64",0) loAsn = createobject("CkAsn") llSuccess = loAsn.LoadEncoded(lcStrBase64,"base64") if (llSuccess <> .T.) then ? loAsn.LastErrorText release loPem release loAsn return endif // Convert the ASN.1 to XML. loXml = createobject("CkXml") llSuccess = loXml.LoadXml(loAsn.AsnToXml()) ? loXml.GetXml() ? "----" lcStrModulusHex = loXml.GetChildContent("bits") ? "strModulusHex = " + lcStrModulusHex ? "----" // We need the modulus as base64. loBd = createobject("CkBinData") loBd.AppendEncoded(lcStrModulusHex,"hex") lcModulus64 = loBd.GetEncoded("base64") ? "modulus64 = " + lcModulus64 ? "----" // Build the XML for the public key. loXmlPubKey = createobject("CkXml") 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. loPubkey = createobject("CkPublicKey") llSuccess = loPubkey.LoadFromString(loXmlPubKey.GetXml()) if (llSuccess <> .T.) then ? loPubkey.LastErrorText release loPem release loAsn release loXml release loBd release loXmlPubKey release loPubkey return endif // Show the public key as PEM. llPreferPkcs1 = .T. ? loPubkey.GetPem(llPreferPkcs1) release loPem release loAsn release loXml release loBd release loXmlPubKey release loPubkey |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.