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
(Tcl) Get Public Key from CSRDemonstrates how to get the public key from a CSR.
load ./chilkat.dll # This requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set pem [new_CkPem] # No password is required. Pass an empty password string.. set noPassword "" set success [CkPem_LoadPemFile $pem "qa_data/csr/csr2.pem" $noPassword] if {$success != 1} then { puts [CkPem_lastErrorText $pem] delete_CkPem $pem exit } set strBase64 [CkPem_getEncodedItem $pem "csr" "" "base64" 0] set asn [new_CkAsn] set success [CkAsn_LoadEncoded $asn $strBase64 "base64"] if {$success != 1} then { puts [CkAsn_lastErrorText $asn] delete_CkPem $pem delete_CkAsn $asn exit } # Convert the ASN.1 to XML. set xml [new_CkXml] set success [CkXml_LoadXml $xml [CkAsn_asnToXml $asn]] puts [CkXml_getXml $xml] puts "----" set strModulusHex [CkXml_getChildContent $xml "bits"] puts "strModulusHex = $strModulusHex" puts "----" # We need the modulus as base64. set bd [new_CkBinData] CkBinData_AppendEncoded $bd $strModulusHex "hex" set modulus64 [CkBinData_getEncoded $bd "base64"] puts "modulus64 = $modulus64" puts "----" # Build the XML for the public key. set xmlPubKey [new_CkXml] CkXml_put_Tag $xmlPubKey "RSAPublicKey" CkXml_UpdateChildContent $xmlPubKey "Modulus" $modulus64 # The RSA exponent will always be decimal 65537 (base64 = AQAB) CkXml_UpdateChildContent $xmlPubKey "Exponent" "AQAB" puts "RSA public key as XML:" puts [CkXml_getXml $xmlPubKey] puts "----" # Load the XML into a Chilkat public key object. set pubkey [new_CkPublicKey] set success [CkPublicKey_LoadFromString $pubkey [CkXml_getXml $xmlPubKey]] if {$success != 1} then { puts [CkPublicKey_lastErrorText $pubkey] delete_CkPem $pem delete_CkAsn $asn delete_CkXml $xml delete_CkBinData $bd delete_CkXml $xmlPubKey delete_CkPublicKey $pubkey exit } # Show the public key as PEM. set preferPkcs1 1 puts [CkPublicKey_getPem $pubkey $preferPkcs1] delete_CkPem $pem delete_CkAsn $asn delete_CkXml $xml delete_CkBinData $bd delete_CkXml $xmlPubKey delete_CkPublicKey $pubkey |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.