DataFlex
DataFlex
Load a JWE from a String
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.LoadJwe, which loads a JWE from its compact serialization string so it can be decrypted.
Background. JWE (JSON Web Encryption) protects content with a content-encryption algorithm (the header
enc value) while the content-encryption key is managed by the key-management algorithm (the header alg value). This example uses AES key wrapping with a symmetric wrapping key.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoJwe
String sJweCompact
String sBase64Key
String sContent
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatJwe)) To hoJwe
If (Not(IsComObjectCreated(hoJwe))) Begin
Send CreateComObject of hoJwe
End
// Load a JWE from its compact serialization string.
Move "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>" To sJweCompact
Get ComLoadJwe Of hoJwe sJweCompact To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoJwe To sTemp1
Showln sTemp1
Procedure_Return
End
// The 256-bit key-wrapping key (base64) for recipient index 0. In production, obtain the key
// from a secure source rather than hard-coding it.
Move "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=" To sBase64Key
Get ComSetWrappingKey Of hoJwe 0 sBase64Key "base64" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoJwe To sTemp1
Showln sTemp1
Procedure_Return
End
// The loaded JWE can now be decrypted.
Get ComDecrypt Of hoJwe 0 "utf-8" To sContent
Get ComLastMethodSuccess Of hoJwe To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoJwe To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sContent
End_Procedure