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) JWE using ECDH-ES, BP-256, A256GCM

See more JSON Web Encryption (JWE) Examples

Create a JWE with the following header:

	{
	  "alg": "ECDH-ES",
	  "enc": "A256GCM",
	  "exp": 1621957030,
	  "cty": "NJWT",
	  "epk": {
	    "kty": "EC",
	    "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"
	    "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
	    "crv": "BP-256"
	  }
	}

Note: This example requires Chilkat v9.5.0.87 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Json
oleobject loo_Pubkey
oleobject loo_Jwt
oleobject loo_JweProtHdr
oleobject loo_Jwe
string ls_PlainText
string ls_StrJwe

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

// Load our brainpool BP-256 public key.

// 	{
// 	  "use": "enc",
// 	  "kid": "puk_idp_enc",
// 	  "kty": "EC",
// 	  "crv": "BP-256",
// 	  "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w",
// 	  "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
// 	}

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Json
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Json.UpdateString("use","enc")
loo_Json.UpdateString("kid","puk_idp_enc")
loo_Json.UpdateString("kty","EC")
loo_Json.UpdateString("crv","BP-256")
loo_Json.UpdateString("x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w")
loo_Json.UpdateString("y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu")

loo_Pubkey = create oleobject
// Use "Chilkat_9_5_0.PublicKey" for versions of Chilkat < 10.0.0
li_rc = loo_Pubkey.ConnectToNewObject("Chilkat.PublicKey")

li_Success = loo_Pubkey.LoadFromString(loo_Json.Emit())
if li_Success = 0 then
    Write-Debug loo_Pubkey.LastErrorText
    destroy loo_Json
    destroy loo_Pubkey
    return
end if

// Build our protected header:

// 	{
// 	  "alg": "ECDH-ES",
// 	  "enc": "A256GCM",
// 	  "exp": 1621957030,
// 	  "cty": "NJWT",
// 	  "epk": {
// 	    "kty": "EC",
// 	    "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w"
// 	    "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu"
// 	    "crv": "BP-256"
// 	  }
// 	}

// Use jwt only for getting the current date/time + 3600 seconds.
loo_Jwt = create oleobject
// Use "Chilkat_9_5_0.Jwt" for versions of Chilkat < 10.0.0
li_rc = loo_Jwt.ConnectToNewObject("Chilkat.Jwt")

loo_JweProtHdr = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JweProtHdr.ConnectToNewObject("Chilkat.JsonObject")

loo_JweProtHdr.UpdateString("alg","ECDH-ES")
loo_JweProtHdr.UpdateString("enc","A256GCM")
loo_JweProtHdr.UpdateInt("exp",loo_Jwt.GenNumericDate(3600))
loo_JweProtHdr.UpdateString("cty","NJWT")
loo_JweProtHdr.UpdateString("epk.kty","EC")
loo_JweProtHdr.UpdateString("epk.x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w")
loo_JweProtHdr.UpdateString("epk.y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu")
loo_JweProtHdr.UpdateString("epk.crv","BP-256")

loo_Jwe = create oleobject
// Use "Chilkat_9_5_0.Jwe" for versions of Chilkat < 10.0.0
li_rc = loo_Jwe.ConnectToNewObject("Chilkat.Jwe")

loo_Jwe.SetProtectedHeader(loo_JweProtHdr)
loo_Jwe.SetPublicKey(0,loo_Pubkey)

ls_PlainText = "This is the text to be encrypted."
ls_StrJwe = loo_Jwe.Encrypt(ls_PlainText,"utf-8")
if loo_Jwe.LastMethodSuccess <> 1 then
    Write-Debug loo_Jwe.LastErrorText
    destroy loo_Json
    destroy loo_Pubkey
    destroy loo_Jwt
    destroy loo_JweProtHdr
    destroy loo_Jwe
    return
end if

Write-Debug ls_StrJwe

Write-Debug "Success."


destroy loo_Json
destroy loo_Pubkey
destroy loo_Jwt
destroy loo_JweProtHdr
destroy loo_Jwe

 

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