JSFiddle - React, Tailwind, and code Playground
JavaScript
var key = 'aaaaaaaaaaaaaaaa'
var iv = 'bbbbbbbbbbbbbbbb';
var ciphertext = '10f42fd95857ed2775cfbc4b471bc213';
function hex2ab(hex){
return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {return parseInt(h, 16)}));
}
key = new TextEncoder().encode(key);
iv = new TextEncoder().encode(iv);
ciphertext = hex2ab(ciphertext);
window.crypto.subtle.importKey(
'raw',
key,
{
name: 'AES-CBC'
},
true, // can the key be extracted using SubtleCrypto.exportKey() / SubtleCrypto.wrapKey()?
['decrypt'] // keyUsages
).then(function(key) {
window.crypto.subtle.decrypt(
{
name: "AES-CBC",
iv: iv
},
key,
ciphertext
).then(function(plaintext) {
console.log(new TextDecoder().decode(plaintext));
})
});