JSFiddle - React, Tailwind, and code Playground
by qayxswedcvfr
HTML
<script src="https://rawgit.com/bitwiseshiftleft/sjcl/master/sjcl.js"></script>
<script src="https://rawgit.com/ForbesLindesay/promisejs.org/master/polyfills/output/promise-7.0.4.min.js"></script>
JavaScript
var iv = base64DecodeToArray("iKZaX3K+X2g6RLxH2Iz2Rg==");
var wrappedKey = base64DecodeToArray("FWPt4AZDKJaN1KssHCBo+ZFSX/rKvh3eLMpOfHILsVYbV7WWSwX8NQ==");
var iterations = parseInt("100000");
var hashAlgorithm = "SHA-256";
var saltString = "d1YQ3JvtIjIdOJkkD7HHrEUnAixTSEz77xp5aGGWoXk=";
var cryptoAlgorithm = "AES-CBC";
getDEK("1q2w3e4r", saltString, iterations, hashAlgorithm, iv, wrappedKey, cryptoAlgorithm, false)
.then(
function (key) {
var encryptedBinary = base64DecodeToArray("f3KxjbNrz0entEYWHnbBHg==");
if (encryptedBinary.byteLength === 0) {
return Promise.resolve(encryptedBinary);
}
// Decrypt the payload
if (window.msCrypto) {
key.oncomplete = function (e) {
return window.msCrypto.subtle.decrypt({ name: cryptoAlgorithm, iv: iv }, new Uint8Array(e.target.result), encryptedBinary);
};
} else {
return crypto.subtle.decrypt({ name: cryptoAlgorithm, iv: iv }, key, encryptedBinary);
}
}
).then(
function (plainBinary) {
if (window.msCrypto) {
plainBinary.oncomplete = function (e) {
// TODO with e.target.result
}
} else {
// TODO with plainBinary
}
}
).catch(
function (err) {
console.err("error");
}
);
function getDEK(password, saltString, iterations, hash,...