Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Get Public Key from CSR

Demonstrates how to get the public key from a CSR.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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
li_rc = loo_Pem.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Asn.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Bd.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_XmlPubKey.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Pubkey.ConnectToNewObject("Chilkat_9_5_0.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.