AutoIt
AutoIt
Decrypt a JWE into BinData
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.DecryptBd, which decrypts a recipient of a loaded JWE and writes the plaintext bytes into a BinData.
Background. This is used when the decrypted content is binary. The recipient key must be provided before decrypting.
Chilkat AutoIt Downloads
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 bytes into a BinData.
$oBd = ObjCreate("Chilkat.BinData")
$bSuccess = $oJwe.DecryptBd(0,$oBd)
If ($bSuccess = False) Then
ConsoleWrite($oJwe.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Decrypted " & $oBd.NumBytes & " bytes." & @CRLF)