Last active
July 30, 2024 06:21
-
-
Save ellemedit/d24e3abd5fe0817c0cab80a87cf07a78 to your computer and use it in GitHub Desktop.
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY Generator
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
// you can run this on latest chrome browser and copy the result | |
function arrayBufferToString(buffer) { | |
const bytes = new Uint8Array(buffer) | |
const len = bytes.byteLength | |
// @anonrig: V8 has a limit of 65535 arguments in a function. | |
// For len < 65535, this is faster. | |
// https://github.com/vercel/next.js/pull/56377#pullrequestreview-1656181623 | |
if (len < 65535) { | |
return String.fromCharCode.apply(null, bytes) | |
} | |
let binary = '' | |
for (let i = 0; i < len; i++) { | |
binary += String.fromCharCode(bytes[i]) | |
} | |
return binary | |
} | |
const key = await crypto.subtle.generateKey( | |
{ | |
name: 'AES-GCM', | |
length: 256, | |
}, | |
true, | |
['encrypt', 'decrypt'] | |
) | |
const exported = await crypto.subtle.exportKey('raw', key) | |
const b64 = btoa(arrayBufferToString(exported)) | |
console.log(b64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment