crypto.subtle.encrypt(algo, key, encoded)
async function encrypt (text, password, mode, length, ivLength) {
var algo = {
name: mode,
length: length,
iv: crypto.getRandomValues(new Uint8Array(ivLength))
};
var key = await genEncryptionKey(password, mode, length);
var encoded = new TextEncoder().encode(text);
return {
cipherText: await crypto.subtle.encrypt(algo, key, encoded),
iv: algo.iv
};
}
async function encrypt (text, password, mode, length, ivLength) {
var algo = {
name: mode,
length: length,
iv: crypto.getRandomValues(new Uint8Array(ivLength))
};
var key = await genEncryptionKey(password, mode, length);
var encoded = new TextEncoder().encode(text);
return {
cipherText: await crypto.subtle.encrypt(algo, key, encoded),
iv: algo.iv
};
}