diff --git a/src/index.ts b/src/index.ts index 3ab92b4..e1e256b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -199,11 +199,15 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport function decodePayload(raw: string): T | undefined { try { const binaryString = atob(raw) - const encodedString = encodeURIComponent(binaryString).replace(/%([0-9A-F]{2})/g, (_match, p1) => { - return String.fromCharCode(parseInt(p1, 16)); - }); + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } - return JSON.parse(decodeURIComponent(encodedString)); + const decoder = new TextDecoder('utf-8'); + const decodedString = decoder.decode(bytes); + + return JSON.parse(decodedString); } catch { return }