mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 12:45:21 +00:00
Remove Buffer from symmetric.ts
This commit is contained in:
parent
c66927668b
commit
ab3b23f100
@ -7,29 +7,29 @@ export const TagSize = 16;
|
|||||||
const Algorithm = { name: "AES-GCM", length: 128 };
|
const Algorithm = { name: "AES-GCM", length: 128 };
|
||||||
|
|
||||||
export async function encrypt(
|
export async function encrypt(
|
||||||
iv: Buffer | Uint8Array,
|
iv: Uint8Array,
|
||||||
key: Buffer,
|
key: Uint8Array,
|
||||||
clearText: Buffer
|
clearText: Uint8Array
|
||||||
): Promise<Buffer> {
|
): Promise<Uint8Array> {
|
||||||
return getSubtle()
|
return getSubtle()
|
||||||
.importKey("raw", key, Algorithm, false, ["encrypt"])
|
.importKey("raw", key, Algorithm, false, ["encrypt"])
|
||||||
.then((cryptoKey) =>
|
.then((cryptoKey) =>
|
||||||
getSubtle().encrypt({ iv, ...Algorithm }, cryptoKey, clearText)
|
getSubtle().encrypt({ iv, ...Algorithm }, cryptoKey, clearText)
|
||||||
)
|
)
|
||||||
.then(Buffer.from);
|
.then((cipher) => new Uint8Array(cipher));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decrypt(
|
export async function decrypt(
|
||||||
iv: Buffer,
|
iv: Uint8Array,
|
||||||
key: Buffer,
|
key: Uint8Array,
|
||||||
cipherText: Buffer
|
cipherText: Uint8Array
|
||||||
): Promise<Buffer> {
|
): Promise<Uint8Array> {
|
||||||
return getSubtle()
|
return getSubtle()
|
||||||
.importKey("raw", key, Algorithm, false, ["decrypt"])
|
.importKey("raw", key, Algorithm, false, ["decrypt"])
|
||||||
.then((cryptoKey) =>
|
.then((cryptoKey) =>
|
||||||
getSubtle().decrypt({ iv, ...Algorithm }, cryptoKey, cipherText)
|
getSubtle().decrypt({ iv, ...Algorithm }, cryptoKey, cipherText)
|
||||||
)
|
)
|
||||||
.then(Buffer.from);
|
.then((clear) => new Uint8Array(clear));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateIv(): Uint8Array {
|
export function generateIv(): Uint8Array {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user