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
(AutoIt) 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. $oPem = ObjCreate("Chilkat.Pem") ; No password is required. Pass an empty password string.. Local $sNoPassword = "" Local $bSuccess = $oPem.LoadPemFile("qa_data/csr/csr2.pem",$sNoPassword) If ($bSuccess <> True) Then ConsoleWrite($oPem.LastErrorText & @CRLF) Exit EndIf Local $strBase64 = $oPem.GetEncodedItem("csr","","base64",0) $oAsn = ObjCreate("Chilkat.Asn") $bSuccess = $oAsn.LoadEncoded($strBase64,"base64") If ($bSuccess <> True) Then ConsoleWrite($oAsn.LastErrorText & @CRLF) Exit EndIf ; Convert the ASN.1 to XML. $oXml = ObjCreate("Chilkat.Xml") $bSuccess = $oXml.LoadXml($oAsn.AsnToXml()) ConsoleWrite($oXml.GetXml() & @CRLF) ConsoleWrite("----" & @CRLF) Local $strModulusHex = $oXml.GetChildContent("bits") ConsoleWrite("strModulusHex = " & $strModulusHex & @CRLF) ConsoleWrite("----" & @CRLF) ; We need the modulus as base64. $oBd = ObjCreate("Chilkat.BinData") $oBd.AppendEncoded($strModulusHex,"hex") Local $sModulus64 = $oBd.GetEncoded("base64") ConsoleWrite("modulus64 = " & $sModulus64 & @CRLF) ConsoleWrite("----" & @CRLF) ; Build the XML for the public key. $oXmlPubKey = ObjCreate("Chilkat.Xml") $oXmlPubKey.Tag = "RSAPublicKey" $oXmlPubKey.UpdateChildContent "Modulus",$sModulus64 ; The RSA exponent will always be decimal 65537 (base64 = AQAB) $oXmlPubKey.UpdateChildContent "Exponent","AQAB" ConsoleWrite("RSA public key as XML:" & @CRLF) ConsoleWrite($oXmlPubKey.GetXml() & @CRLF) ConsoleWrite("----" & @CRLF) ; Load the XML into a Chilkat public key object. $oPubkey = ObjCreate("Chilkat.PublicKey") $bSuccess = $oPubkey.LoadFromString($oXmlPubKey.GetXml()) If ($bSuccess <> True) Then ConsoleWrite($oPubkey.LastErrorText & @CRLF) Exit EndIf ; Show the public key as PEM. Local $bPreferPkcs1 = True ConsoleWrite($oPubkey.GetPem($bPreferPkcs1) & @CRLF) |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.