Remove Buffer from symmetric.ts

This commit is contained in:
Franck Royer 2022-05-19 16:07:30 +10:00
parent c66927668b
commit ab3b23f100
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 10 additions and 10 deletions

View File

@ -7,29 +7,29 @@ export const TagSize = 16;
const Algorithm = { name: "AES-GCM", length: 128 };
export async function encrypt(
iv: Buffer | Uint8Array,
key: Buffer,
clearText: Buffer
): Promise<Buffer> {
iv: Uint8Array,
key: Uint8Array,
clearText: Uint8Array
): Promise<Uint8Array> {
return getSubtle()
.importKey("raw", key, Algorithm, false, ["encrypt"])
.then((cryptoKey) =>
getSubtle().encrypt({ iv, ...Algorithm }, cryptoKey, clearText)
)
.then(Buffer.from);
.then((cipher) => new Uint8Array(cipher));
}
export async function decrypt(
iv: Buffer,
key: Buffer,
cipherText: Buffer
): Promise<Buffer> {
iv: Uint8Array,
key: Uint8Array,
cipherText: Uint8Array
): Promise<Uint8Array> {
return getSubtle()
.importKey("raw", key, Algorithm, false, ["decrypt"])
.then((cryptoKey) =>
getSubtle().decrypt({ iv, ...Algorithm }, cryptoKey, cipherText)
)
.then(Buffer.from);
.then((clear) => new Uint8Array(clear));
}
export function generateIv(): Uint8Array {