Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) JWE using ECDH-ES, BP-256, A256GCMSee more JSON Web Encryption (JWE) ExamplesCreate 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.
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.