Switch to AES-128 for shorter decryption keys in URLs (backwards compatible)

This commit is contained in:
ComputerTech 2026-03-28 01:08:21 +00:00
parent 7803f97714
commit f8cc163ba9
1 changed files with 4 additions and 2 deletions

View File

@ -46,7 +46,7 @@ const PasteCrypto = (function () {
/** Generate a new, random AES-GCM 256-bit key. */
async generateKey() {
return window.crypto.subtle.generateKey(
{ name: 'AES-GCM', length: 256 },
{ name: 'AES-GCM', length: 128 },
true,
['encrypt', 'decrypt']
);
@ -61,10 +61,12 @@ const PasteCrypto = (function () {
/** Import a base64url key string into a CryptoKey for decryption. */
async importKey(keyBase64url) {
const keyBytes = base64urlToArrayBuffer(keyBase64url);
// Support both old 256-bit and new 128-bit keys automatically
const keyLength = keyBytes.byteLength * 8;
return window.crypto.subtle.importKey(
'raw',
keyBytes,
{ name: 'AES-GCM', length: 256 },
{ name: 'AES-GCM', length: keyLength },
false,
['decrypt']
);