59 lines
1.8 KiB
HTML
59 lines
1.8 KiB
HTML
<html>
|
|
<header>
|
|
<meta charset="UTF-8">
|
|
<script>
|
|
function b64tobuff(b64) {
|
|
binary = window.atob(b64)
|
|
return stobuff(binary)
|
|
}
|
|
function stobuff(s) {
|
|
bytes = new Uint8Array(s.length)
|
|
for (var i = 0; i < s.length; i++) {
|
|
bytes[i] = s.charCodeAt(i)
|
|
}
|
|
return bytes.buffer
|
|
}
|
|
|
|
key = "123".repeat(32).substr(0, 32)
|
|
console.log("key:", key)
|
|
ciphertext = atob("SOY05yF/9iv3YG71sKkQPVaEwO53PCX8qZhDHS9JUohBgVl5Qr9/GTKK/TJ6OozhHN7QBIGmHNzQxTRRSLs4Lw==")
|
|
console.log("ciphertext:", ciphertext)
|
|
data = ciphertext.substr(12, ciphertext.length)
|
|
nonce = ciphertext.substr(0, 12)
|
|
console.log("data:", data)
|
|
console.log("nonce:", nonce)
|
|
|
|
key = crypto.subtle.importKey(
|
|
"raw",
|
|
stobuff(key),
|
|
"AES-GCM",
|
|
false,
|
|
["decrypt"],
|
|
).then(function(cryptoKey) {
|
|
console.log("cryptoKey:", cryptoKey)
|
|
window.crypto.subtle.decrypt(
|
|
{
|
|
name: "AES-GCM",
|
|
iv: stobuff(nonce),
|
|
},
|
|
cryptoKey,
|
|
stobuff(data),
|
|
).then(function(decrypted) {
|
|
console.log(decrypted)
|
|
console.log(String.fromCharCode.apply(null, new Uint8Array(decrypted)))
|
|
})
|
|
.catch(function(eb){
|
|
console.log("eb:",eb.code, eb.message, eb.name)
|
|
})
|
|
})
|
|
.catch(function(ea){console.log("ea:",ea.code, ea.message, ea.name)})
|
|
</script>
|
|
</header>
|
|
<body>
|
|
<div id="display">
|
|
</div>
|
|
</body>
|
|
<footer>
|
|
</footer>
|
|
</html>
|