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 * @internal
*/ */
export async function encryptAsymmetric( export async function encryptAsymmetric(
data: Uint8Array | Buffer, data: Uint8Array,
publicKey: Uint8Array | Buffer | string publicKey: Uint8Array | string
): Promise<Uint8Array> { ): 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 * @internal
*/ */
export async function encryptSymmetric( export async function encryptSymmetric(
data: Uint8Array | Buffer, data: Uint8Array,
key: Uint8Array | Buffer | string key: Uint8Array | string
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const iv = symmetric.generateIv(); const iv = symmetric.generateIv();
// Returns `cipher | tag` // Returns `cipher | tag`
const cipher = await symmetric.encrypt( const cipher = await symmetric.encrypt(iv, hexToBytes(key), data);
iv, return concat([cipher, iv]);
Buffer.from(hexToBytes(key)),
Buffer.from(data)
);
return Buffer.concat([cipher, Buffer.from(iv)]);
} }
/** /**