mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
19 lines
779 B
TypeScript
19 lines
779 B
TypeScript
async function doTest(additionalData) {
|
|
const name = "AES-GCM";
|
|
const key = await crypto.subtle.generateKey({ name, length: 128 }, false, ["encrypt", "decrypt"]);
|
|
const plaintext = new Uint8Array();
|
|
const iv = crypto.getRandomValues(new Uint8Array(16));
|
|
const algorithm = { name, iv, tagLength: 128, additionalData };
|
|
const ciphertext = await crypto.subtle.encrypt(algorithm, key, plaintext);
|
|
const decrypted = await crypto.subtle.decrypt(algorithm, key, ciphertext);
|
|
expect(new TextDecoder().decode(decrypted)).toBe("");
|
|
}
|
|
|
|
it("crypto.subtle.encrypt AES-GCM empty data", async () => {
|
|
doTest(undefined);
|
|
});
|
|
|
|
it("crypto.subtle.encrypt AES-GCM empty data with additional associated data", async () => {
|
|
doTest(crypto.getRandomValues(new Uint8Array(16)));
|
|
});
|