Доработать вложенные файлы и архив проекта

This commit is contained in:
AidarKC
2026-09-11 14:33:21 +03:00
parent f9ae811702
commit ef068eca81
22 changed files with 3865 additions and 216 deletions
+8 -4
View File
@@ -289,15 +289,19 @@ export async function importAesKeyRaw(keyBytes, usages = ['encrypt', 'decrypt'])
return getSubtleApi().importKey('raw', keyBytes, { name: 'AES-GCM' }, false, usages);
}
export async function encryptBytesAesGcm(plainBytes, keyBytes, ivBytes) {
export async function encryptBytesAesGcm(plainBytes, keyBytes, ivBytes, additionalData = null) {
const key = await importAesKeyRaw(keyBytes, ['encrypt']);
const cipher = await getSubtleApi().encrypt({ name: 'AES-GCM', iv: ivBytes }, key, plainBytes);
const algorithm = { name: 'AES-GCM', iv: ivBytes };
if (additionalData) algorithm.additionalData = additionalData;
const cipher = await getSubtleApi().encrypt(algorithm, key, plainBytes);
return new Uint8Array(cipher);
}
export async function decryptBytesAesGcm(cipherBytes, keyBytes, ivBytes) {
export async function decryptBytesAesGcm(cipherBytes, keyBytes, ivBytes, additionalData = null) {
const key = await importAesKeyRaw(keyBytes, ['decrypt']);
const plain = await getSubtleApi().decrypt({ name: 'AES-GCM', iv: ivBytes }, key, cipherBytes);
const algorithm = { name: 'AES-GCM', iv: ivBytes };
if (additionalData) algorithm.additionalData = additionalData;
const plain = await getSubtleApi().decrypt(algorithm, key, cipherBytes);
return new Uint8Array(plain);
}