Created
April 9, 2025 14:13
-
-
Save dzmitry-savitski/caeef097b285609687d901db21768f36 to your computer and use it in GitHub Desktop.
Revisions
-
dzmitry-savitski created this gist
Apr 9, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import { jwtDecrypt } from 'jose'; // Your base64-encoded 256-bit key (should decode to 32 bytes) const base64Key = 'yourBase64EncodedKeyHere'; // example: "3q2+7w==..." // Decode base64 to a Uint8Array const key = Uint8Array.from(Buffer.from(base64Key, 'base64')); // Your JWE compact token const token = 'eyJalgIjoiZGlyIiwiZW5jIjoiQTI1NkdDTSJ9..<IV>.<ciphertext>.<tag>'; async function decrypt() { const { payload, protectedHeader } = await jwtDecrypt(token, key); console.log('🔓 Decrypted payload:', new TextDecoder().decode(payload)); console.log('📄 Header:', protectedHeader); } decrypt().catch(err => console.error('Decryption failed:', err));