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

 

 

 

(PowerBuilder) Create JWK Set Containing Certificates

Demonstrates how to create a JWK Set containing N certificates.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Cert1
integer li_Success
oleobject loo_Cert2
oleobject loo_Crypt
oleobject loo_Json
string ls_HexThumbprint
string ls_Base64Thumbprint
oleobject loo_PubKey
oleobject loo_PubKeyJwk

// This example creates the following JWK Set from two certificates:

// {
//   "keys": [
//     {
//       "kty": "RSA",
//       "use": "sig",
//       "kid": "BB8CeFVqyaGrGNuehJIiL4dfjzw",
//       "x5t": "BB8CeFVqyaGrGNuehJIiL4dfjzw",
//       "n": "nYf1jpn7cFdQ...9Iw",
//       "e": "AQAB",
//       "x5c": [
//         "MIIDBTCCAe2...Z+NTZo"
//       ]
//     },
//     {
//       "kty": "RSA",
//       "use": "sig",
//       "kid": "M6pX7RHoraLsprfJeRCjSxuURhc",
//       "x5t": "M6pX7RHoraLsprfJeRCjSxuURhc",
//       "n": "xHScZMPo8F...EO4QQ",
//       "e": "AQAB",
//       "x5c": [
//         "MIIC8TCCAdmgA...Vt5432GA=="
//       ]
//     }
//   ]
// }

// First get two certificates from files.
loo_Cert1 = create oleobject
li_rc = loo_Cert1.ConnectToNewObject("Chilkat_9_5_0.Cert")
if li_rc < 0 then
    destroy loo_Cert1
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Cert1.LoadFromFile("qa_data/certs/brasil_cert.pem")
if li_Success <> 1 then
    Write-Debug loo_Cert1.LastErrorText
    destroy loo_Cert1
    return
end if

loo_Cert2 = create oleobject
li_rc = loo_Cert2.ConnectToNewObject("Chilkat_9_5_0.Cert")

li_Success = loo_Cert2.LoadFromFile("qa_data/certs/testCert.cer")
if li_Success <> 1 then
    Write-Debug loo_Cert2.LastErrorText
    destroy loo_Cert1
    destroy loo_Cert2
    return
end if

// We'll need this crypt object re-encode the SHA1 thumbprint from hex to base64.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

// Let's begin with the 1st cert:
loo_Json.I = 0
loo_Json.UpdateString("keys[i].kty","RSA")
loo_Json.UpdateString("keys[i].use","sig")

ls_HexThumbprint = loo_Cert1.Sha1Thumbprint
ls_Base64Thumbprint = loo_Crypt.ReEncode(ls_HexThumbprint,"hex","base64")
loo_Json.UpdateString("keys[i].kid",ls_Base64Thumbprint)
loo_Json.UpdateString("keys[i].x5t",ls_Base64Thumbprint)

// (We're assuming these are RSA certificates)
// To get the modulus (n) and exponent (e), we need to get the cert's public key and then get its JWK.
loo_PubKey = loo_Cert1.ExportPublicKey()
loo_PubKeyJwk = create oleobject
li_rc = loo_PubKeyJwk.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_PubKeyJwk.Load(loo_PubKey.GetJwk())
destroy loo_PubKey
loo_Json.UpdateString("keys[i].n",loo_PubKeyJwk.StringOf("n"))
loo_Json.UpdateString("keys[i].e",loo_PubKeyJwk.StringOf("e"))

// Now add the entire X.509 certificate 
loo_Json.UpdateString("keys[i].x5c[0]",loo_Cert1.GetEncoded())

// Now do the same for cert2..
loo_Json.I = 1

loo_Json.UpdateString("keys[i].kty","RSA")
loo_Json.UpdateString("keys[i].use","sig")

ls_HexThumbprint = loo_Cert2.Sha1Thumbprint
ls_Base64Thumbprint = loo_Crypt.ReEncode(ls_HexThumbprint,"hex","base64")
loo_Json.UpdateString("keys[i].kid",ls_Base64Thumbprint)
loo_Json.UpdateString("keys[i].x5t",ls_Base64Thumbprint)

loo_PubKey = loo_Cert2.ExportPublicKey()
loo_PubKeyJwk.Load(loo_PubKey.GetJwk())
destroy loo_PubKey
loo_Json.UpdateString("keys[i].n",loo_PubKeyJwk.StringOf("n"))
loo_Json.UpdateString("keys[i].e",loo_PubKeyJwk.StringOf("e"))

// Now add the entire X.509 certificate 
loo_Json.UpdateString("keys[i].x5c[0]",loo_Cert2.GetEncoded())

// Emit the JSON..
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()


destroy loo_Cert1
destroy loo_Cert2
destroy loo_Crypt
destroy loo_Json
destroy loo_PubKeyJwk

 

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