fix(encryption): improve encryption security: adjust salt size and memory parameters for AES encryption

This commit is contained in:
2026-03-05 22:03:32 -05:00
parent eef98030d6
commit b54c12ba10
+10 -8
View File
@@ -20,8 +20,8 @@ function fromBase64(data: string): Uint8Array {
export async function encryptAES(content: string, password: string): Promise<string> { export async function encryptAES(content: string, password: string): Promise<string> {
const enc = new TextEncoder(); const enc = new TextEncoder();
const salt = window.crypto.getRandomValues(new Uint8Array(32)); const salt = window.crypto.getRandomValues(new Uint8Array(16));
const memorySize = 65536; const memorySize = 262144;
const iterations = 3; const iterations = 3;
const parallelism = 1; const parallelism = 1;
@@ -37,8 +37,8 @@ export async function encryptAES(content: string, password: string): Promise<str
const key = await window.crypto.subtle.importKey( const key = await window.crypto.subtle.importKey(
'raw', 'raw',
keyMaterial as unknown as BufferSource, new Uint8Array(keyMaterial),
{ name: 'AES-GCM' }, { name: 'AES-GCM', length: 256 },
false, false,
['encrypt'] ['encrypt']
); );
@@ -47,7 +47,8 @@ export async function encryptAES(content: string, password: string): Promise<str
const encryptedContent = await window.crypto.subtle.encrypt( const encryptedContent = await window.crypto.subtle.encrypt(
{ {
name: 'AES-GCM', name: 'AES-GCM',
iv iv,
additionalData: enc.encode('enc-v4')
}, },
key, key,
enc.encode(content) enc.encode(content)
@@ -127,8 +128,8 @@ export async function decryptAES(result: string, password: string): Promise<stri
const key = await window.crypto.subtle.importKey( const key = await window.crypto.subtle.importKey(
'raw', 'raw',
keyMaterial as unknown as BufferSource, new Uint8Array(keyMaterial),
{ name: 'AES-GCM' }, { name: 'AES-GCM', length: 256 },
false, false,
['decrypt'] ['decrypt']
); );
@@ -136,7 +137,8 @@ export async function decryptAES(result: string, password: string): Promise<stri
const decryptedContent = await window.crypto.subtle.decrypt( const decryptedContent = await window.crypto.subtle.decrypt(
{ {
name: 'AES-GCM', name: 'AES-GCM',
iv iv,
additionalData: enc.encode('enc-v4')
}, },
key, key,
data data