SHA256
Доработать вложенные файлы и архив проекта
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user