Commit e726df33 authored by Daniel Hofmann's avatar Daniel Hofmann
Browse files

JS nosalt, plaintext from user

parent ab94277e
......@@ -10,24 +10,44 @@
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
</head>
<body>
<p>check console for now!</p>
<input id="plaintext" type="text" name="plaintext" autofocus="autofocus" placeholder="My Secret..">
<p id="ciphertext"></p>
<p id="key"></p>
</body>
<script>
"use strict";
var plaintext = 'Hello';
var key = '0000000000000000';
var iv = '0000000000000000';
var bs = 16; // aes block size is 16 bytes
var opts = { iv: iv,
keySize: 128 / 8,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7 };
document.getElementById('plaintext').onkeypress = function(e) {
var event = e || window.event;
var charCode = event.which || event.keyCode;
if (charCode == '13') { // enter pressed
var plaintext = document.getElementById("plaintext").value;
var enc = CryptoJS.AES.encrypt(plaintext, key, opts);
// note: no need for a key derivation functioni, we're _generating_ a key from scratch _every time_
var key = CryptoJS.lib.WordArray.random(bs);
var iv = CryptoJS.lib.WordArray.random(bs);
console.log({key: key, iv: iv, plaintext: plaintext});
console.log(enc.toString())
var opts = {iv: iv, keySize: bs, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7};
var enc = CryptoJS.AES.encrypt(plaintext, key, opts);
console.log('ciphertext: ' + enc.ciphertext.toString(CryptoJS.enc.Hex));
console.log('key: ' + enc.key.toString(CryptoJS.enc.Hex));
console.log('iv: ' + enc.iv.toString(CryptoJS.enc.Hex));
/* note:
- no need for urlencode, hex is perfectly fine for urls
- decoding: unhex 'out', first 16 bytes are iv, rest is ciphertext
- or: split 'out', unhex first 32 bytes for iv, unhex rest for ciphertext
*/
var out = enc.iv.toString(CryptoJS.enc.Hex) + enc.ciphertext.toString(CryptoJS.enc.Hex);
document.getElementById("ciphertext").textContent = 'iv + ciphertext: ' + out;
document.getElementById("key").textContent = 'key: ' + enc.key.toString(CryptoJS.enc.Hex);
}
}
</script>
</html>
<!-- vim: set tabstop=4 shiftwidth=4 expandtab: --!>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment