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
(PowerBuilder) Get Public Key from CSRDemonstrates how to get the public key from a CSR.
integer li_rc oleobject loo_Pem string ls_NoPassword integer li_Success string ls_StrBase64 oleobject loo_Asn oleobject loo_Xml string ls_StrModulusHex oleobject loo_Bd string ls_Modulus64 oleobject loo_XmlPubKey oleobject loo_Pubkey integer li_PreferPkcs1 // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Pem = create oleobject // Use "Chilkat_9_5_0.Pem" for versions of Chilkat < 10.0.0 li_rc = loo_Pem.ConnectToNewObject("Chilkat.Pem") if li_rc < 0 then destroy loo_Pem MessageBox("Error","Connecting to COM object failed") return end if // No password is required. Pass an empty password string.. ls_NoPassword = "" li_Success = loo_Pem.LoadPemFile("qa_data/csr/csr2.pem",ls_NoPassword) if li_Success <> 1 then Write-Debug loo_Pem.LastErrorText destroy loo_Pem return end if ls_StrBase64 = loo_Pem.GetEncodedItem("csr","","base64",0) loo_Asn = create oleobject // Use "Chilkat_9_5_0.Asn" for versions of Chilkat < 10.0.0 li_rc = loo_Asn.ConnectToNewObject("Chilkat.Asn") li_Success = loo_Asn.LoadEncoded(ls_StrBase64,"base64") if li_Success <> 1 then Write-Debug loo_Asn.LastErrorText destroy loo_Pem destroy loo_Asn return end if // Convert the ASN.1 to XML. loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") li_Success = loo_Xml.LoadXml(loo_Asn.AsnToXml()) Write-Debug loo_Xml.GetXml() Write-Debug "----" ls_StrModulusHex = loo_Xml.GetChildContent("bits") Write-Debug "strModulusHex = " + ls_StrModulusHex Write-Debug "----" // We need the modulus as base64. loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_Bd.AppendEncoded(ls_StrModulusHex,"hex") ls_Modulus64 = loo_Bd.GetEncoded("base64") Write-Debug "modulus64 = " + ls_Modulus64 Write-Debug "----" // Build the XML for the public key. loo_XmlPubKey = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlPubKey.ConnectToNewObject("Chilkat.Xml") loo_XmlPubKey.Tag = "RSAPublicKey" loo_XmlPubKey.UpdateChildContent("Modulus",ls_Modulus64) // The RSA exponent will always be decimal 65537 (base64 = AQAB) loo_XmlPubKey.UpdateChildContent("Exponent","AQAB") Write-Debug "RSA public key as XML:" Write-Debug loo_XmlPubKey.GetXml() Write-Debug "----" // Load the XML into a Chilkat public key object. loo_Pubkey = create oleobject // Use "Chilkat_9_5_0.PublicKey" for versions of Chilkat < 10.0.0 li_rc = loo_Pubkey.ConnectToNewObject("Chilkat.PublicKey") li_Success = loo_Pubkey.LoadFromString(loo_XmlPubKey.GetXml()) if li_Success <> 1 then Write-Debug loo_Pubkey.LastErrorText destroy loo_Pem destroy loo_Asn destroy loo_Xml destroy loo_Bd destroy loo_XmlPubKey destroy loo_Pubkey return end if // Show the public key as PEM. li_PreferPkcs1 = 1 Write-Debug loo_Pubkey.GetPem(li_PreferPkcs1) destroy loo_Pem destroy loo_Asn destroy loo_Xml destroy loo_Bd destroy loo_XmlPubKey destroy loo_Pubkey |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.