mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-13 12:07:05 +02:00
23 lines
587 B
JavaScript
23 lines
587 B
JavaScript
// run with `pnpm -r token:jwt`
|
|
|
|
const makeSecureString = (length = 64) => {
|
|
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
|
const out = [];
|
|
|
|
while (out.length < length) {
|
|
for (const byte of crypto.getRandomValues(new Uint8Array(length))) {
|
|
if (byte < alphabet.length) {
|
|
out.push(alphabet[byte]);
|
|
}
|
|
|
|
if (out.length === length) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return out.join('');
|
|
}
|
|
|
|
console.log(`JWT_SECRET: ${JSON.stringify(makeSecureString(64))}`)
|