@hackbg/miscreant-esm
Version:
(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions
22 lines (21 loc) • 655 B
JavaScript
import {WebCryptoProvider} from "./providers/webcrypto.dist.mjs";
import {SIV} from "./siv.dist.mjs";
export class AEAD {
static async importKey(keyData, alg, provider = new WebCryptoProvider()) {
return new AEAD(await SIV.importKey(keyData, alg, provider));
}
_siv;
constructor(siv) {
this._siv = siv;
}
async seal(plaintext, nonce, associatedData = new Uint8Array(0)) {
return this._siv.seal(plaintext, [associatedData, nonce]);
}
async open(ciphertext, nonce, associatedData = new Uint8Array(0)) {
return this._siv.open(ciphertext, [associatedData, nonce]);
}
clear() {
this._siv.clear();
return this;
}
}