-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaes_test.html
119 lines (112 loc) · 6.17 KB
/
aes_test.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="description" content="Frankie Po : ">
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-ecb.js"></script>
<!---<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-ofb.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-cfb.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-ctr-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-iso97971.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-iso10126.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-zeropadding.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-ansix923.js"></script>-->
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pad-nopadding.js"></script>
<style>
table, td {
border: 1px solid black;
width: 100%;
text-align: left;
}
</style>
<!--<link rel="stylesheet" type="text/css" href="stylesheets/style.css">-->
<title>Test AES length</title>
</head>
<body>
<h1>AES Test</h1>
<br>
<h2>Test phases:</h2>
<table id="output_modes"></table>
<script>
var message = '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var keyString = '8914014603208505383835449615862032396298230312463794048875383939165708770313';
var IV = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');
var encryptedMsg;
var decryptedMsg;
/* You can ennable decrypted messages output */
var encryptDebug = true;
var decryptDebug = true;
// var modes = ['CBC','CFB', 'CTR', 'OFB', 'ECB'];
// var paddings = ['Pkcs7', 'Iso10126', 'AnsiX923', 'Iso97971', 'ZeroPadding', 'NoPadding'];
encryptedMsg = CryptoJS.AES.encrypt(message, keyString,
{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.NoPadding, iv: IV });
var tablem = document.getElementById("output_modes");
/* Test different modes */
var header = tablem.createTHead();
//var headrow = header.insertRow();
//headrow.insertCell().innerHTML = "Mode";
//headrow.insertCell().innerHTML = "Length";
var row = tablem.insertRow(0);
row.insertCell(0).innerHTML = 'Length: ' + message.length.toString() + ', Message(utf-8): ';
row.insertCell(1).innerHTML = message;
var row = tablem.insertRow(1);
row.insertCell(0).innerHTML = 'Length: ' + encryptedMsg.ciphertext.toString().length.toString() + ', Ciphertext(hex):';
row.insertCell(1).innerHTML = encryptedMsg.ciphertext.toString();
var row = tablem.insertRow(2);
row.insertCell(0).innerHTML = 'Length: ' + encryptedMsg.ciphertext.toString(CryptoJS.enc.Base64).length.toString() + ', Ciphertext(Base64):';
row.insertCell(1).innerHTML = encryptedMsg.ciphertext.toString(CryptoJS.enc.Base64);
var row = tablem.insertRow(3);
row.insertCell(0).innerHTML = 'Length: ' + encryptedMsg.toString().length.toString() + ', Encrypted Message:';
row.insertCell(1).innerHTML = encryptedMsg.toString();
//if (encryptDebug) headrow.insertCell().innerHTML = "Encrypted";
//if (decryptDebug) headrow.insertCell().innerHTML = "Decrypted";
/*for (var i = 0; i < 20; i++)
{
encryptedMsg = CryptoJS.AES.encrypt(message, keyString,
{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.NoPadding, iv: IV });
var row = tablem.insertRow();
// row.insertCell().innerHTML = modes[i];
row.insertCell().innerHTML = encryptedMsg.toString();
if (encryptDebug) {
row.insertCell().innerHTML = encryptedMsg.ciphertext.toString(CryptoJS.enc.Base64);
// console.log(encryptedMsg);
}
if (decryptDebug) {
decryptedMsg = CryptoJS.AES.decrypt(encryptedMsg.ciphertext, keyString,
{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.NoPadding, iv: IV });
row.insertCell().innerHTML = decryptedMsg.toString(CryptoJS.enc.Utf8);
// sconsole.log(decryptedMsg.toString(CryptoJS.enc.Utf8).length + ':' + decryptedMsg.toString(CryptoJS.enc.Utf8));
}
}*/
/*
var tablep = document.getElementById("output_paddings");
var header = tablep.createTHead();
var headrow = header.insertRow();
headrow.insertCell().innerHTML = "Padding";
headrow.insertCell().innerHTML = "Length";
if (encryptDebug) headrow.insertCell().innerHTML = "Encrypted";
if (decryptDebug) headrow.insertCell().innerHTML = "Decrypted";
// Test different paddings
for (var i = 0; i < modes.length; i++)
{
encryptedMsg = CryptoJS.AES.encrypt(message, keyString,
{ mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[paddings[i]], iv: IV });
var row = tablep.insertRow(i+1);
row.insertCell().innerHTML = paddings[i];
row.insertCell().innerHTML = encryptedMsg.toString().length;
if (encryptDebug) {
row.insertCell().innerHTML = encryptedMsg.toString();
// console.log(encryptedMsg.toString().length + ':' + encryptedMsg.toString());
}
if (decryptDebug) {
decryptedMsg = CryptoJS.AES.decrypt(encryptedMsg.toString(), keyString,
{ mode: CryptoJS.mode.ECB, padding: CryptoJS.pad[paddings[i]], iv: IV });
row.insertCell().innerHTML = decryptedMsg.toString(CryptoJS.enc.Utf8);
//console.log(decryptedMsg.toString(CryptoJS.enc.Utf8).length + ':' + decryptedMsg.toString(CryptoJS.enc.Utf8));
}
}*/
</script>
</body>
</html>