CTR | (async () => {
let ciphertext;
let counter;
const message = "esto es prueba";
let enc = new TextEncoder();
let encoded = enc.encode(message);
const key = await window.crypto.subtle.generateKey(
{
name: "AES-CTR",
length: 256
},
true,
["encrypt", "decrypt"]
);
counter = window.crypto.getRandomValues(new Uint8Array(16));
ciphertext = await window.crypto.subtle.encrypt(
{
name: "AES-CTR",
counter,
length: 64
},
key,
encoded
);
})();
| ready |
GCM | (async () => {
let ciphertext;
let iv;
const message = "esto es prueba";
let enc = new TextEncoder();
const key = await window.crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"]
);
let encoded = enc.encode(message);
iv = window.crypto.getRandomValues(new Uint8Array(12));
ciphertext = await window.crypto.subtle.encrypt(
{
name: "AES-GCM",
iv: iv
},
key,
encoded
);
})();
| ready |
CBC | (async () => {
let ciphertext;
let iv;
const message = "esto es prueba";
let enc = new TextEncoder();
const key = await window.crypto.subtle.generateKey(
{
name: "AES-CBC",
length: 256
},
true,
["encrypt", "decrypt"]
);
let encoded = enc.encode(message);
iv = window.crypto.getRandomValues(new Uint8Array(16));
ciphertext = await window.crypto.subtle.encrypt(
{
name: "AES-CBC",
iv
},
key,
encoded
);
})();
| ready |