forked from ComputerTech/bastebin
Switch to AES-128 for shorter decryption keys in URLs (backwards compatible)
This commit is contained in:
parent
7803f97714
commit
f8cc163ba9
|
|
@ -46,7 +46,7 @@ const PasteCrypto = (function () {
|
||||||
/** Generate a new, random AES-GCM 256-bit key. */
|
/** Generate a new, random AES-GCM 256-bit key. */
|
||||||
async generateKey() {
|
async generateKey() {
|
||||||
return window.crypto.subtle.generateKey(
|
return window.crypto.subtle.generateKey(
|
||||||
{ name: 'AES-GCM', length: 256 },
|
{ name: 'AES-GCM', length: 128 },
|
||||||
true,
|
true,
|
||||||
['encrypt', 'decrypt']
|
['encrypt', 'decrypt']
|
||||||
);
|
);
|
||||||
|
|
@ -61,10 +61,12 @@ const PasteCrypto = (function () {
|
||||||
/** Import a base64url key string into a CryptoKey for decryption. */
|
/** Import a base64url key string into a CryptoKey for decryption. */
|
||||||
async importKey(keyBase64url) {
|
async importKey(keyBase64url) {
|
||||||
const keyBytes = base64urlToArrayBuffer(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(
|
return window.crypto.subtle.importKey(
|
||||||
'raw',
|
'raw',
|
||||||
keyBytes,
|
keyBytes,
|
||||||
{ name: 'AES-GCM', length: 256 },
|
{ name: 'AES-GCM', length: keyLength },
|
||||||
false,
|
false,
|
||||||
['decrypt']
|
['decrypt']
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue