diff --git a/static/js/crypto.js b/static/js/crypto.js index 57d83f1..60f8406 100644 --- a/static/js/crypto.js +++ b/static/js/crypto.js @@ -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'] );