Created
April 9, 2025 14:13
-
-
Save dzmitry-savitski/caeef097b285609687d901db21768f36 to your computer and use it in GitHub Desktop.
Decrypt jwt
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 characters
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment