Sample code for 30+ languages & platforms
AutoIt

Decrypt a JWE into a StringBuilder

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.DecryptSb, which decrypts a recipient of a loaded JWE and writes the plaintext into a StringBuilder.

Background. The recipient index selects which recipient's key material to use. The key for that recipient must be provided before decrypting.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oJwe = ObjCreate("Chilkat.Jwe")

;  Load the JWE compact serialization to be decrypted.
Local $sJweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
$bSuccess = $oJwe.LoadJwe($sJweCompact)
If ($bSuccess = False) Then
    ConsoleWrite($oJwe.LastErrorText & @CRLF)
    Exit
EndIf

;  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.
Local $sBase64Key = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU="
$bSuccess = $oJwe.SetWrappingKey(0,$sBase64Key,"base64")
If ($bSuccess = False) Then
    ConsoleWrite($oJwe.LastErrorText & @CRLF)
    Exit
EndIf

;  Decrypt recipient index 0, writing the plaintext into a StringBuilder.
$oSbContent = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oJwe.DecryptSb(0,"utf-8",$oSbContent)
If ($bSuccess = False) Then
    ConsoleWrite($oJwe.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($oSbContent.GetAsString() & @CRLF)