-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.en.html
More file actions
76 lines (65 loc) · 2.58 KB
/
demo.en.html
File metadata and controls
76 lines (65 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Cryptools AES Demo (browser)</title>
<style>
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial; padding: 24px; }
pre { background:#f6f8fa; padding:12px; border-radius:6px; white-space:pre-wrap; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
</style>
</head>
<body>
<h1>Cryptools AES Demo (AES-GCM + Argon2id)</h1>
<p>
This demo uses the <code>window.Cryptools</code> bundle. Make sure your
<code>bundle.min.js</code> is loaded and that it attaches
<code>window.Cryptools</code>.
</p>
<pre id="output"></pre>
<script src="speedups.js"></script> <!-- load speedups -->
<script type="module">
import './bundle.min.js'; // <-- your bundle that sets window.Cryptools
const out = document.getElementById('output');
const log = (s='') => { out.textContent += String(s) + '\n'; };
out.textContent = 'starting…\n';
async function main() {
// Sanity check the bundle
if (!window.Cryptools?.AES?.encrypt || !window.Cryptools?.AES?.decrypt) {
log('❌ window.Cryptools.AES.encrypt/decrypt not found.');
log(' Did your bundle attach window.Cryptools correctly?');
return;
}
const msg = 'Hello from Cryptools AES 👋';
const password = 'correct horse battery staple';
log('➡️ plaintext: ' + msg);
log('➡️ password: ' + password);
log('\n⏳ Waiting for speedups to load…');
await window.speedups_loaded;
try {
log('\n🔐 Encrypting…');
const combinedBase64 = await window.Cryptools.AES.encrypt(msg, password);
log('✅ ciphertext (salt+iv+ciphertext, Base64):');
log(combinedBase64);
log('\n🔓 Decrypting…');
const decrypted = await window.Cryptools.AES.decrypt(combinedBase64, password);
log('✅ decrypted: ' + decrypted);
log('✔️ round-trip OK: ' + (decrypted === msg));
log('\n🧪 Decrypting with wrong password (should fail)…');
try {
await window.Cryptools.AES.decrypt(combinedBase64, 'wrong password');
log('⚠️ unexpected: decrypt succeeded with wrong password!');
} catch (e) {
log('✅ expected failure: ' + (e && e.message ? e.message : e));
}
} catch (e) {
log('❌ error: ' + (e && e.message ? e.message : e));
console.error(e);
}
}
// Kick it off
main();
</script>
</body>
</html>