ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [ {
switch (aeadAlg) {
case "AES128GCM":
return [
{
encrypt(key, nonce, aad, plaintext) {
return encryptAesGcm(key, nonce, aad, plaintext);
},
decrypt(key, nonce, aad, ciphertext) {
return decryptAesGcm(key, nonce, aad, ciphertext);
},
},
new Aes128Gcm(),
];
case "AES256GCM":
return [
{
encrypt(key, nonce, aad, plaintext) {
return encryptAesGcm(key, nonce, aad, plaintext);
},
decrypt(key, nonce, aad, ciphertext) {
return decryptAesGcm(key, nonce, aad, ciphertext);
},
},
new Aes256Gcm(),
];
case "CHACHA20POLY1305":
try {
const { Chacha20Poly1305 } = await import("@hpke/chacha20poly1305");
const { chacha20poly1305 } = await import("@noble/ciphers/chacha.js");
return [
{
async encrypt(key, nonce, aad, plaintext) {
return chacha20poly1305(key, nonce, aad).encrypt(plaintext);
},
async decrypt(key, nonce, aad, ciphertext) {
return chacha20poly1305(key, nonce, aad).decrypt(ciphertext);
},
},
new Chacha20Poly1305(),
];
}
catch (err) {
throw new DependencyError("Optional dependency '@hpke/chacha20poly1305' is not installed. Please install it to use this feature.");
}
}
}
async function encryptAesGcm(key, nonce, aad, plaintext) {
const cipher = gcm(key, nonce, aad);
return cipher.encrypt(plaintext);
}
async function decryptAesGcm(key, nonce, aad, ciphertext) {
const cipher = gcm(key, nonce, aad);
return cipher.decrypt(ciphertext);
}
//# sourceMappingURL=makeAead.js.map