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
Cloud Signature CSC
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
Secrets
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) Create JCEKS Containing Secret Keys

Demonstrates how to create a JCEKS keystore file containing symmetric secret keys (for AES, Blowfish, HMAC SHA25, ChaCha20, etc.)

This example requires Chilkat v9.5.0.66 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Jceks
oleobject loo_Prng
string ls_AesKey
string ls_BlowfishKey
string ls_HmacKey
string ls_ChachaKey
string ls_Encoding
string ls_Password
string ls_FilePassword
integer li_Success
oleobject loo_SbJson
oleobject loo_Json

// IMPORTANT: This example requires Chilkat v9.5.0.66 or greater.

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

loo_Jceks = create oleobject
// Use "Chilkat_9_5_0.JavaKeyStore" for versions of Chilkat < 10.0.0
li_rc = loo_Jceks.ConnectToNewObject("Chilkat.JavaKeyStore")
if li_rc < 0 then
    destroy loo_Jceks
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// We'll need a pseudo-random number generator (PRNG) to generate symmetric keys.
loo_Prng = create oleobject
// Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0
li_rc = loo_Prng.ConnectToNewObject("Chilkat.Prng")

// Generate some keys..

// 128-bit AES key (16 bytes)
ls_AesKey = loo_Prng.GenRandom(16,"base64")

// 256-bit Blowfish key (32 bytes)
ls_BlowfishKey = loo_Prng.GenRandom(32,"base64")

// HMAC SHA256 key
// (An HMAC key can be anything, and any length. We'll use the following string:
ls_HmacKey = "This is my HMAC key"

// ChaCha20 256-bit
ls_ChachaKey = loo_Prng.GenRandom(32,"base64")

// Add each secret key to the JCEKS
ls_Encoding = "base64"
ls_Password = "secret"
loo_Jceks.AddSecretKey(ls_AesKey,ls_Encoding,"AES","my aes key",ls_Password)
loo_Jceks.AddSecretKey(ls_BlowfishKey,ls_Encoding,"BLOWFISH","my blowfish key",ls_Password)
// For HMAC, we're using the us-ascii bytes for the key..
loo_Jceks.AddSecretKey(ls_HmacKey,"ascii","HMAC_SHA256","my hmac key",ls_Password)
loo_Jceks.AddSecretKey(ls_ChachaKey,ls_Encoding,"CHACHA","my chacha20 key",ls_Password)

ls_FilePassword = "password"
// Write the JCEKs to a file.
li_Success = loo_Jceks.ToFile(ls_FilePassword,"qa_output/secretKeys.jceks")
if li_Success <> 1 then
    Write-Debug loo_Jceks.LastErrorText
    destroy loo_Jceks
    destroy loo_Prng
    return
end if

// We can also emit as a JWK Set..
loo_SbJson = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Jceks.ToJwkSet("secret",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Jceks.LastErrorText
    destroy loo_Jceks
    destroy loo_Prng
    destroy loo_SbJson
    return
end if

// Emit the JSON in pretty-printed (indented) form:
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbJson)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()

// Output is:

// { 
//   "keys": [
//     { 
//       "kty": "oct",
//       "alg": "AES",
//       "k": "vHekQQB0Gc1NvppapUTW2g",
//       "kid": "my aes key"
//     },
//     { 
//       "kty": "oct",
//       "alg": "BLOWFISH",
//       "k": "qHsdXaJsXicVCZbK8l8hJQpYOa0GkiO9gsRK9WLtht8",
//       "kid": "my blowfish key"
//     },
//     { 
//       "kty": "oct",
//       "alg": "HMAC_SHA256",
//       "k": "VGhpcyBpcyBteSBITUFDIGtleQ",
//       "kid": "my hmac key"
//     },
//     { 
//       "kty": "oct",
//       "alg": "CHACHA",
//       "k": "yNv832U43C9BcWvaQAH2_rG-GwfmpgT5JBRllWGQY1o",
//       "kid": "my chacha20 key"
//     }
//   ]
// }
// 


destroy loo_Jceks
destroy loo_Prng
destroy loo_SbJson
destroy loo_Json

 

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