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 JWS with Multiple Signatures using the General JSON Serialization Format

Creates a JSON Web Signature (JWS) containing 3 signatures and output using the general JSON serialization format.

Chilkat supports all of the following JWS algorithms:

   +--------------+-------------------------------+--------------------+
   | "alg" Param  | Digital Signature or MAC      | Implementation     |
   | Value        | Algorithm                     | Requirements       |
   +--------------+-------------------------------+--------------------+
   | HS256        | HMAC using SHA-256            | Required           |
   | HS384        | HMAC using SHA-384            | Optional           |
   | HS512        | HMAC using SHA-512            | Optional           |
   | RS256        | RSASSA-PKCS1-v1_5 using       | Recommended        |
   |              | SHA-256                       |                    |
   | RS384        | RSASSA-PKCS1-v1_5 using       | Optional           |
   |              | SHA-384                       |                    |
   | RS512        | RSASSA-PKCS1-v1_5 using       | Optional           |
   |              | SHA-512                       |                    |
   | ES256        | ECDSA using P-256 and SHA-256 | Recommended+       |
   | ES384        | ECDSA using P-384 and SHA-384 | Optional           |
   | ES512        | ECDSA using P-521 and SHA-512 | Optional           |
   | PS256        | RSASSA-PSS using SHA-256 and  | Optional           |
   |              | MGF1 with SHA-256             |                    |
   | PS384        | RSASSA-PSS using SHA-384 and  | Optional           |
   |              | MGF1 with SHA-384             |                    |
   | PS512        | RSASSA-PSS using SHA-512 and  | Optional           |
   |              | MGF1 with SHA-512             |                    |
   +--------------+-------------------------------+--------------------+

Note: 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_SbRsaJwk
oleobject loo_RsaKey
integer li_Success
oleobject loo_SbEccJwk
oleobject loo_EccKey
string ls_HmacKey
oleobject loo_JwsProtHdr0
oleobject loo_JwsUnprotHdr0
oleobject loo_JwsProtHdr1
oleobject loo_JwsUnprotHdr1
oleobject loo_JwsProtHdr2
oleobject loo_JwsUnprotHdr2
oleobject loo_Jws
integer li_BIncludeBom
string ls_PayloadStr
string ls_JwsStr
oleobject loo_Json

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

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

// The JWS to be created will contain three signatures.
// The 1st will use an ECC key, the 2nd an RSA key, and the 3rd an HMAC key.

// Prepare each key..

// ---------------------------------------------------
// Use the following RSA key loaded from JWK format.
loo_SbRsaJwk = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRsaJwk.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_SbRsaJwk
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_SbRsaJwk.Append("{~"kty~":~"RSA~",")
loo_SbRsaJwk.Append("~"n~":~"ofgWCuLjybRlzo0tZWJjNiuSfb4p4fAkd_wWJcyQoTbji9k0l8W26mPddx")
loo_SbRsaJwk.Append("HmfHQp-Vaw-4qPCJrcS2mJPMEzP1Pt0Bm4d4QlL-yRT-SFd2lZS-pCgNMs")
loo_SbRsaJwk.Append("D1W_YpRPEwOWvG6b32690r2jZ47soMZo9wGzjb_7OMg0LOL-bSf63kpaSH")
loo_SbRsaJwk.Append("SXndS5z5rexMdbBYUsLA9e-KXBdQOS-UTo7WTBEMa2R2CapHg665xsmtdV")
loo_SbRsaJwk.Append("MTBQY4uDZlxvb3qCo5ZwKh9kG4LT6_I5IhlJH7aGhyxXFvUK-DWNmoudF8")
loo_SbRsaJwk.Append("NAco9_h9iaGNj8q2ethFkMLs91kzk2PAcDTW9gb54h4FRWyuXpoQ~",")
loo_SbRsaJwk.Append("~"e~":~"AQAB~",")
loo_SbRsaJwk.Append("~"d~":~"Eq5xpGnNCivDflJsRQBXHx1hdR1k6Ulwe2JZD50LpXyWPEAeP88vLNO97I")
loo_SbRsaJwk.Append("jlA7_GQ5sLKMgvfTeXZx9SE-7YwVol2NXOoAJe46sui395IW_GO-pWJ1O0")
loo_SbRsaJwk.Append("BkTGoVEn2bKVRUCgu-GjBVaYLU6f3l9kJfFNS3E0QbVdxzubSu3Mkqzjkn")
loo_SbRsaJwk.Append("439X0M_V51gfpRLI9JYanrC4D4qAdGcopV_0ZHHzQlBjudU2QvXt4ehNYT")
loo_SbRsaJwk.Append("CBr6XCLQUShb1juUO1ZdiYoFaFQT5Tw8bGUl_x_jTj3ccPDVZFD9pIuhLh")
loo_SbRsaJwk.Append("BOneufuBiB4cS98l2SR_RQyGWSeWjnczT0QU91p1DhOVRuOopznQ~",")
loo_SbRsaJwk.Append("~"p~":~"4BzEEOtIpmVdVEZNCqS7baC4crd0pqnRH_5IB3jw3bcxGn6QLvnEtfdUdi")
loo_SbRsaJwk.Append("YrqBdss1l58BQ3KhooKeQTa9AB0Hw_Py5PJdTJNPY8cQn7ouZ2KKDcmnPG")
loo_SbRsaJwk.Append("BY5t7yLc1QlQ5xHdwW1VhvKn-nXqhJTBgIPgtldC-KDV5z-y2XDwGUc~",")
loo_SbRsaJwk.Append("~"q~":~"uQPEfgmVtjL0Uyyx88GZFF1fOunH3-7cepKmtH4pxhtCoHqpWmT8YAmZxa")
loo_SbRsaJwk.Append("ewHgHAjLYsp1ZSe7zFYHj7C6ul7TjeLQeZD_YwD66t62wDmpe_HlB-TnBA")
loo_SbRsaJwk.Append("-njbglfIsRLtXlnDzQkv5dTltRJ11BKBBypeeF6689rjcJIDEz9RWdc~",")
loo_SbRsaJwk.Append("~"dp~":~"BwKfV3Akq5_MFZDFZCnW-wzl-CCo83WoZvnLQwCTeDv8uzluRSnm71I3Q")
loo_SbRsaJwk.Append("CLdhrqE2e9YkxvuxdBfpT_PI7Yz-FOKnu1R6HsJeDCjn12Sk3vmAktV2zb")
loo_SbRsaJwk.Append("34MCdy7cpdTh_YVr7tss2u6vneTwrA86rZtu5Mbr1C1XsmvkxHQAdYo0~",")
loo_SbRsaJwk.Append("~"dq~":~"h_96-mK1R_7glhsum81dZxjTnYynPbZpHziZjeeHcXYsXaaMwkOlODsWa")
loo_SbRsaJwk.Append("7I9xXDoRwbKgB719rrmI2oKr6N3Do9U0ajaHF-NKJnwgjMd2w9cjz3_-ky")
loo_SbRsaJwk.Append("NlxAr2v4IKhGNpmM5iIgOS1VZnOZ68m6_pbLBSp3nssTdlqvd0tIiTHU~",")
loo_SbRsaJwk.Append("~"qi~":~"IYd7DHOhrWvxkwPQsRM2tOgrjbcrfvtQJipd-DlcxyVuuM9sQLdgjVk2o")
loo_SbRsaJwk.Append("y26F0EmpScGLq2MowX7fhd_QJQ3ydy5cY7YIBi87w93IKLEdfnbJtoOPLU")
loo_SbRsaJwk.Append("W0ITrJReOgo1cq9SbsxYawBgfp_gh6A5603k2-ZQwVK0JKSHuLFkuQ3U~"")
loo_SbRsaJwk.Append("}")

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

// Note: This example loads the RSA key from JWK format.  Any format can be loaded
// into the private key object. (See the online reference documentation..)
li_Success = loo_RsaKey.LoadJwk(loo_SbRsaJwk.GetAsString())
if li_Success <> 1 then
    Write-Debug loo_RsaKey.LastErrorText
    destroy loo_SbRsaJwk
    destroy loo_RsaKey
    return
end if

// ---------------------------------------------------
// Use the following ECC key loaded from JWK format.
loo_SbEccJwk = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbEccJwk.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbEccJwk.Append("{~"kty~":~"EC~",")
loo_SbEccJwk.Append("~"crv~":~"P-256~",")
loo_SbEccJwk.Append("~"x~":~"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU~",")
loo_SbEccJwk.Append("~"y~":~"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0~",")
loo_SbEccJwk.Append("~"d~":~"jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI~"")
loo_SbEccJwk.Append("}")

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

// Note: This example loads the ECDSA key from JWK format.  Any format can be loaded
// into the private key object. (See the online reference documentation..)
li_Success = loo_EccKey.LoadJwk(loo_SbEccJwk.GetAsString())
if li_Success <> 1 then
    Write-Debug loo_EccKey.LastErrorText
    destroy loo_SbRsaJwk
    destroy loo_RsaKey
    destroy loo_SbEccJwk
    destroy loo_EccKey
    return
end if

// ---------------------------------------------------
// The HMAC key (in base64url format)
ls_HmacKey = "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow"

// ---------------------------------------------------
// Prepare the headers..
// RSASSA-PKCS1-v1_5 SHA-256
loo_JwsProtHdr0 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsProtHdr0.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsProtHdr0.AppendString("alg","RS256")
loo_JwsUnprotHdr0 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsUnprotHdr0.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsUnprotHdr0.AppendString("kid","myRsaKey")

// ECDSA using P-256 and SHA-256
loo_JwsProtHdr1 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsProtHdr1.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsProtHdr1.AppendString("alg","ES256")
loo_JwsUnprotHdr1 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsUnprotHdr1.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsUnprotHdr1.AppendString("kid","myEcKey")

// HMAC using SHA-256
loo_JwsProtHdr2 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsProtHdr2.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsProtHdr2.AppendString("alg","HS256")
loo_JwsUnprotHdr2 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JwsUnprotHdr2.ConnectToNewObject("Chilkat.JsonObject")

loo_JwsUnprotHdr2.AppendString("kid","myMacKey")

// ---------------------------------------------------
// First set the JWS headers, keys, and payload, then we'll create the JWS...
loo_Jws = create oleobject
// Use "Chilkat_9_5_0.Jws" for versions of Chilkat < 10.0.0
li_rc = loo_Jws.ConnectToNewObject("Chilkat.Jws")

loo_Jws.SetProtectedHeader(0,loo_JwsProtHdr0)
loo_Jws.SetUnprotectedHeader(0,loo_JwsUnprotHdr0)
loo_Jws.SetProtectedHeader(1,loo_JwsProtHdr1)
loo_Jws.SetUnprotectedHeader(1,loo_JwsUnprotHdr1)
loo_Jws.SetProtectedHeader(2,loo_JwsProtHdr2)
loo_Jws.SetUnprotectedHeader(2,loo_JwsUnprotHdr2)

loo_Jws.SetPrivateKey(0,loo_RsaKey)
loo_Jws.SetPrivateKey(1,loo_EccKey)
loo_Jws.SetMacKey(2,ls_HmacKey,"base64url")

li_BIncludeBom = 0
ls_PayloadStr = "In our village, folks say God crumbles up the old moon into stars."
loo_Jws.SetPayload(ls_PayloadStr,"utf-8",li_BIncludeBom)

// ---------------------------------------------------
// Create the JWS.
// Givent that multiple signatures will exist, only the general JSON serialization 
// format is possible, and that is what will be produced.
ls_JwsStr = loo_Jws.CreateJws()
if loo_Jws.LastMethodSuccess <> 1 then
    Write-Debug loo_Jws.LastErrorText
    destroy loo_SbRsaJwk
    destroy loo_RsaKey
    destroy loo_SbEccJwk
    destroy loo_EccKey
    destroy loo_JwsProtHdr0
    destroy loo_JwsUnprotHdr0
    destroy loo_JwsProtHdr1
    destroy loo_JwsUnprotHdr1
    destroy loo_JwsProtHdr2
    destroy loo_JwsUnprotHdr2
    destroy loo_Jws
    return
end if

// The jwsStr is contains JSON in the smallest possible size, which is a single line.
// To get in human-readable format, load into a Chilkat JSON object and emit..
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.Load(ls_JwsStr)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()

// Sample output:

// { 
//   "payload": "SW4gb3VyIHZpbGxhZ2UsIGZvbGtzIHNheSBHb2QgY3J1bWJsZXMgdXAgdGhlIG9sZCBtb29uIGludG8gc3RhcnMu",
//   "signatures": [
//     { 
//       "protected": "eyJhbGciOiJSUzI1NiJ9",
//       "header": { 
//         "kid": "myRsaKey"
//       },
//       "signature": "B04c24gSnpVm1Z-_bemfyNMCpZm6Knj1yB-yzaIOvijsWfDgoF_mSJccTIbzapNgwJudnobr5iDOfZWiRR9iqCyDJLe5M1S40vFF7MFEI3JecYRgrRc6n1lTkYLMRyVq48BwbQlmKgPqmK9drun3agklsr0FmgNx65pfmcnlYdXsgwxf8WbgppefrlrMImp-98-dNtBcUL8ce1aOjbcyVFjGMCzpm3JerQqIzWQvEwBstnMEQle73KHcyx_nsTmlzY70CaydbRTsciOATL7WfiMwuX1q9Y2NIpTg3CbOTWKdwjh7iyfiAKQxNBaF2mApnqj9hjpf8GwR-CfxAzJtPg"
//     },
//     { 
//       "protected": "eyJhbGciOiJFUzI1NiJ9",
//       "header": { 
//         "kid": "myEcKey"
//       },
//       "signature": "2cbugKq0ERaQMh01n2B-86EZFYleeMf8bsccaQMxzOxAg14PxfjR3IImvodTJYqkmfBJYW203etz2-7ZtJUOGw"
//     },
//     { 
//       "protected": "eyJhbGciOiJIUzI1NiJ9",
//       "header": { 
//         "kid": "myMacKey"
//       },
//       "signature": "e7R9gjx0RsUNa3c7qd8k9mQGEhtcG8vsN1W7jbLb2MA"
//     }
//   ]
// }


destroy loo_SbRsaJwk
destroy loo_RsaKey
destroy loo_SbEccJwk
destroy loo_EccKey
destroy loo_JwsProtHdr0
destroy loo_JwsUnprotHdr0
destroy loo_JwsProtHdr1
destroy loo_JwsUnprotHdr1
destroy loo_JwsProtHdr2
destroy loo_JwsUnprotHdr2
destroy loo_Jws
destroy loo_Json

 

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