Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Visual FoxPro Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Visual FoxPro) 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

LOCAL loPem
LOCAL lcNoPassword
LOCAL lnSuccess
LOCAL lcStrBase64
LOCAL loAsn
LOCAL loXml
LOCAL lcStrModulusHex
LOCAL loBd
LOCAL lcModulus64
LOCAL loXmlPubKey
LOCAL loPubkey
LOCAL lnPreferPkcs1

*  This requires the Chilkat API to have been previously unlocked.
*  See Global Unlock Sample for sample code.

loPem = CreateObject('Chilkat_9_5_0.Pem')

*  No password is required.  Pass an empty password string..
lcNoPassword = ""
lnSuccess = loPem.LoadPemFile("qa_data/csr/myCsr.pem",lcNoPassword)
IF (lnSuccess <> 1) THEN
    ? loPem.LastErrorText
    RELEASE loPem
    CANCEL
ENDIF

lcStrBase64 = loPem.GetEncodedItem("csr","","base64",0)

loAsn = CreateObject('Chilkat_9_5_0.Asn')
lnSuccess = loAsn.LoadEncoded(lcStrBase64,"base64")
IF (lnSuccess <> 1) THEN
    ? loAsn.LastErrorText
    RELEASE loPem
    RELEASE loAsn
    CANCEL
ENDIF

*  Convert the ASN.1 to XML.
loXml = CreateObject('Chilkat_9_5_0.Xml')
lnSuccess = loXml.LoadXml(loAsn.AsnToXml())
? loXml.GetXml()
? "----"

lcStrModulusHex = loXml.GetChildContent("bits")
? "strModulusHex = " + lcStrModulusHex
? "----"

*  We need the modulus as base64.
loBd = CreateObject('Chilkat_9_5_0.BinData')
loBd.AppendEncoded(lcStrModulusHex,"hex")
lcModulus64 = loBd.GetEncoded("base64")
? "modulus64 = " + lcModulus64
? "----"

*  Build the XML for the public key.
loXmlPubKey = CreateObject('Chilkat_9_5_0.Xml')
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('Chilkat_9_5_0.PublicKey')
lnSuccess = loPubkey.LoadFromString(loXmlPubKey.GetXml())
IF (lnSuccess <> 1) THEN
    ? loPubkey.LastErrorText
    RELEASE loPem
    RELEASE loAsn
    RELEASE loXml
    RELEASE loBd
    RELEASE loXmlPubKey
    RELEASE loPubkey
    CANCEL
ENDIF

*  Show the public key as PEM.
lnPreferPkcs1 = 1
? loPubkey.GetPem(lnPreferPkcs1)

RELEASE loPem
RELEASE loAsn
RELEASE loXml
RELEASE loBd
RELEASE loXmlPubKey
RELEASE loPubkey


 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.