Remove `Buffer` from `encrypt*`

This commit is contained in:
Franck Royer 2022-05-19 16:21:09 +10:00
parent 5d32877357
commit 181ba489be
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 7 additions and 11 deletions

View File

@ -118,10 +118,10 @@ export function clearDecode(
* @internal
*/
export async function encryptAsymmetric(
data: Uint8Array | Buffer,
publicKey: Uint8Array | Buffer | string
data: Uint8Array,
publicKey: Uint8Array | string
): Promise<Uint8Array> {
return ecies.encrypt(Buffer.from(hexToBytes(publicKey)), Buffer.from(data));
return ecies.encrypt(hexToBytes(publicKey), data);
}
/**
@ -147,18 +147,14 @@ export async function decryptAsymmetric(
* @internal
*/
export async function encryptSymmetric(
data: Uint8Array | Buffer,
key: Uint8Array | Buffer | string
data: Uint8Array,
key: Uint8Array | string
): Promise<Uint8Array> {
const iv = symmetric.generateIv();
// Returns `cipher | tag`
const cipher = await symmetric.encrypt(
iv,
Buffer.from(hexToBytes(key)),
Buffer.from(data)
);
return Buffer.concat([cipher, Buffer.from(iv)]);
const cipher = await symmetric.encrypt(iv, hexToBytes(key), data);
return concat([cipher, iv]);
}
/**