ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [;
const key256 = randomBytes(32);
const nonce = randomBytes(12);
const aad = randomBytes(12);
const plaintext = new TextEncoder().encode("Hello world!");
test("AES128-GCM encryption and decryption", async () => {
const aead = await makeAead("AES128GCM");
const ciphertext = await aead.encrypt(key128, nonce, new Uint8Array(), plaintext);
const decrypted = await aead.decrypt(key128, nonce, new Uint8Array(), ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
test("AES256-GCM encryption and decryption", async () => {
const aead = await makeAead("AES256GCM");
const ciphertext = await aead.encrypt(key256, nonce, new Uint8Array(), plaintext);
const decrypted = await aead.decrypt(key256, nonce, new Uint8Array(), ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
test("ChaCha20-Poly1305 encryption and decryption", async () => {
const aead = await makeAead("CHACHA20POLY1305");
const ciphertext = await aead.encrypt(key256, nonce, new Uint8Array(), plaintext);
const decrypted = await aead.decrypt(key256, nonce, new Uint8Array(), ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
test("AES128-GCM encryption and decryption with aad", async () => {
const aead = await makeAead("AES128GCM");
const ciphertext = await aead.encrypt(key128, nonce, aad, plaintext);
const decrypted = await aead.decrypt(key128, nonce, aad, ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
test("AES256-GCM encryption and decryption with aad", async () => {
const aead = await makeAead("AES256GCM");
const ciphertext = await aead.encrypt(key256, nonce, aad, plaintext);
const decrypted = await aead.decrypt(key256, nonce, aad, ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
test("ChaCha20-Poly1305 encryption and decryption with aad", async () => {
const aead = await makeAead("CHACHA20POLY1305");
const ciphertext = await aead.encrypt(key256, nonce, aad, plaintext);
const decrypted = await aead.decrypt(key256, nonce, aad, ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("Hello world!");
});
//# sourceMappingURL=aead.test.js.map