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
(Visual Basic 6.0) 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.
' This requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. Dim success As Long ' Load our brainpool BP-256 public key. ' { ' "use": "enc", ' "kid": "puk_idp_enc", ' "kty": "EC", ' "crv": "BP-256", ' "x": "QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w", ' "y": "AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu" ' } Dim json As New ChilkatJsonObject success = json.UpdateString("use","enc") success = json.UpdateString("kid","puk_idp_enc") success = json.UpdateString("kty","EC") success = json.UpdateString("crv","BP-256") success = json.UpdateString("x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w") success = json.UpdateString("y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu") Dim pubkey As New PublicKey success = pubkey.LoadFromString(json.Emit()) If (success = 0) Then Debug.Print pubkey.LastErrorText Exit Sub 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. Dim jwt As New ChilkatJwt Dim jweProtHdr As New ChilkatJsonObject success = jweProtHdr.UpdateString("alg","ECDH-ES") success = jweProtHdr.UpdateString("enc","A256GCM") success = jweProtHdr.UpdateInt("exp",jwt.GenNumericDate(3600)) success = jweProtHdr.UpdateString("cty","NJWT") success = jweProtHdr.UpdateString("epk.kty","EC") success = jweProtHdr.UpdateString("epk.x","QLpJ_LpFx-6yJhsb4OvHwU1khLnviiOwYOvmf5clK7w") success = jweProtHdr.UpdateString("epk.y","AJh7pJ3zZKDJkm8rbeG69GBooTosXJgSsvNFH0i3Vxnu") success = jweProtHdr.UpdateString("epk.crv","BP-256") Dim jwe As New ChilkatJwe success = jwe.SetProtectedHeader(jweProtHdr) success = jwe.SetPublicKey(0,pubkey) Dim plainText As String plainText = "This is the text to be encrypted." Dim strJwe As String strJwe = jwe.Encrypt(plainText,"utf-8") If (jwe.LastMethodSuccess <> 1) Then Debug.Print jwe.LastErrorText Exit Sub End If Debug.Print strJwe Debug.Print "Success." |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.