summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
Unidiff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/Base.html') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/Base.html428
1 files changed, 428 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html b/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
new file mode 100644
index 0000000..86fc49a
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
@@ -0,0 +1,428 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27-->
28
29<html>
30<head>
31 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
38 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
39
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
44
45</head>
46<body>
47<pre id="test">
48<script type="text/javascript">
49try {
50 var secretKey;
51 varpublicKey;
52 varplainString;
53 varencryptedString;
54
55
56 secretKey = "s3cr37k39";
57 plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
58 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
59
60 //-------------------------------------------------------------------------
61 //
62 //Secret key encryption / decryption
63 //
64 is (isUndefinedOrNull(encryptedString), false, "An encrypted string should not be empty");
65 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
66
67 try {
68 vardecryptedText;
69
70 decryptedText = Clipperz.Crypto.Base.decryptUsingSecretKey("anotherKey", encryptedString);
71 ok( false, "It should not be possible to decrypt a text with a different passphrase (decrypted text: " + decryptedText + ")" );
72 } catch (e) {
73 ok( e instanceof Error, "Trying to decrypt a message with the wrong passphrase raised an error" );
74 }
75
76 is (encryptedString == Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString), false, "Two consecutive encryption of the same text should return different values");
77
78 secretKey = "trustno1";
79 plainString = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1";
80 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
81 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
82
83 secretKey = "trustno1";
84 plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.";
85 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
86 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
87
88 secretKey = "trustno1";
89 plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas./n/n/nMorbi vel leo non justo condimentum convallis. Vestibulum posuere aliquam nunc. Donec magna magna, euismod nec, pharetra fringilla, tristique mattis, turpis. Duis condimentum lacus eu felis. Sed ultricies. Nullam lacinia ante id diam. Ut quis enim. Fusce at felis quis neque vehicula tempor. Sed feugiat sodales sem. Duis cursus massa in ligula. Vestibulum volutpat, risus in ornare porta, tortor orci vestibulum felis, et eleifend risus odio nec eros. Integer lorem turpis, imperdiet eu, tempor eu, ultricies nec, est. Ut congue. Morbi lacinia vehicula pede. Cras neque sapien, feugiat ac, eleifend eget, mattis et, nisl. Morbi at augue vitae massa laoreet gravida./n/n/nSuspendisse vehicula convallis sem. Sed vel urna. Proin dolor diam, malesuada in, aliquet a, sagittis et, magna. Cras at dui eu mi porta fermentum. Donec pharetra purus sed velit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque euismod ornare neque. In odio nisi, bibendum non, vulputate ut, tincidunt a, ante. Sed risus arcu, tempus laoreet, euismod id, laoreet mollis, arcu. Ut tempor orci in nibh. Suspendisse potenti. Maecenas accumsan augue at nisl. Donec elementum diam nec metus. Sed vitae lacus sed libero varius semper. Aenean hendrerit tristique arcu. Praesent adipiscing ornare purus. Vestibulum quis eros nec risus accumsan laoreet. Duis consequat ante ut turpis. Curabitur aliquam suscipit ligula. Vivamus adipiscing./n/n/nCurabitur facilisis neque sit amet erat. Aliquam odio augue, vulputate lobortis, rutrum ut, tristique id, leo. Vivamus eu magna. Maecenas et libero. Integer porta, lorem at mollis ullamcorper, purus metus vestibulum erat, ut fringilla dui ante id mi. Morbi vitae ligula. Praesent ornare sapien sed massa. Mauris rhoncus fermentum dolor. Mauris gravida, justo et mollis malesuada, dolor erat fermentum nulla, vel suscipit leo ligula vel augue. Praesent magna enim, dignissim sed, aliquet quis, fermentum viverra, nisi. Vivamus condimentum, nisi quis posuere viverra, enim nunc faucibus lectus, mollis aliquam ipsum enim vel lacus. Suspendisse eget ligula. Aliquam ut metus et justo consectetuer ornare. Donec dapibus tristique pede. Vestibulum interdum ultricies tortor./n/n/nNunc nonummy dictum tortor. Quisque at elit a arcu nonummy elementum. Quisque auctor, risus et sodales euismod, turpis tellus consectetuer ante, quis egestas justo enim quis mi. Nunc fermentum sodales felis. Vivamus odio mi, dignissim vitae, auctor nec, tempus eget, lacus. Ut sapien massa, hendrerit eget, sagittis at, eleifend condimentum, arcu. Curabitur purus orci, facilisis vel, dapibus id, varius rutrum, tortor. Fusce accumsan viverra sem. Quisque tincidunt venenatis risus. Sed tortor justo, volutpat malesuada, sodales ut, vehicula id, magna. Nunc placerat, nibh et imperdiet ultricies, urna nulla luctus sapien, et porta mi odio ac neque. Morbi dignissim. Sed risus pede, adipiscing gravida, pharetra sit amet, convallis non, orci. Morbi adipiscing mauris id massa. Nullam fermentum. Suspendisse eget est";
90 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
91 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
92
93 //secretKey = "trustno1";
94 //plainString = "{}";
95 // plainString = "{'tags': {'personal': ['ref_1', 'ref_3'], 'business': ['ref_2', 'ref_3']}, 'records': {'ref_1': {'label': 'record_1', 'key': 'key_1'}, 'ref_2': {'label': 'record_2', 'key': 'key_2'}, 'ref_3': {'label': 'record_3', 'key': 'key_3'}}}";
96 //plainString = "{'tags': {}, 'records': {'07a5a92fcb334f757998ba14f3251f126d038318b3ac5e584bd712804c548084': {'label': 'Un bel record', 'key': '2a3f261c20a6a98dcc82b13fba013130b759f20602b4b13c5760879e087482a4'}}}";
97 //encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
98 //is(encryptedString, "{}", "encrypted value");
99
100
101 //secretKey = "trustno1";
102 //encryptedString = "0d43a4544424ffa519f2e43b7a46f703884fd94ff9879479563f6f252a573b253d3e77bc4f5f30f17bd11d2907718921ab8c9e1faccbe4314793fa323eb85eaf1bfbce5f7deea601e15b781782181cbff3c649dafef39abb70e8573e4f9be220f2286b01c3bd51d5c4a79b9d44a27be3b0994667302e301ca3dc074fb1bc7abc03d12b9e58ba0249435a120858c96e8ae99570718541499ab958a8fb92b63390be070ff61fc6ef107061693ab14c1915118cc6671ab7cf99b9cca553d6b5a7c314bffcd933e0a59f056d842a47cfe8571110b4764c5225443210d99b43b80a23c20fe953de3e1329d72cfb20139fe1ca";
103 //plainString = Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString);
104 //is(plainString, "{}", "decrypted value");
105
106 //-------------------------------------------------------------------------
107 //
108 //Java secret key encryption / JavaScript decryption
109 //
110 secretKey = "s3cr37k39";
111 plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
112 encryptedString = "9be538c3dde4dfab9384c0ef71dc624299fbbe71be8d1fe8991fd6cae88a883cf459d7cd56913a2b69815782cf74d7ce5c2c08034661f7f8aa59cf420e913086896840ebb45102d44d733d32de2a7dc8";
113 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
114
115 //-------------------------------------------------------------------------
116 //
117 //Public key encryption -> Private key decryption
118 //
119 {
120 varcleanKey;
121 vart1, t2;
122/*
123 //
124 // 128
125 //
126 cleanKey = "248d6a61d20638b8e5c026930c3e6039"; //a33ce45964ff2167f6ecedd419db06c1";
127 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
128 "10001",
129 "202700adbd85e2d7182720c3a0ee19c1",
130 "30db31542ace0f7d37a629ee5eba28cb"
131 );
132 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
133
134 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 128");
135 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 128");
136 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 128");
137*/
138/*
139 //
140 // 256
141 //
142 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
143 cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
144 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
145 "10001",
146 "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
147 "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
148 );
149 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
150
151 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 256");
152 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 256");
153 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 256");
154*/
155/*
156 //
157 //512
158 //
159 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
160 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
161 "10001",
162 "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
163 "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
164 );
165t1 = new Date().getTime();
166 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
167t2 = new Date().getTime();
168//is("Encrypting with public key (512)", (t2 - t1));
169
170 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 512");
171t1 = new Date().getTime();
172 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 512");
173t2 = new Date().getTime();
174//is("Decrypting with private key (512)", (t2 - t1));
175 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 512");
176*/
177/*
178 //
179 //1024
180 //
181 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
182 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
183 "10001",
184 "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
185 "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
186 );
187t1 = new Date().getTime();
188 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
189t2 = new Date().getTime();
190is("Encrypting with public key (1024)", (t2 - t1));
191
192 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 1024");
193t1 = new Date().getTime();
194 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 1024");
195t2 = new Date().getTime();
196is("Decrypting with private key (1024)", (t2 - t1));
197 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 1024");
198*/
199/*
200 //
201 //2048
202 //
203 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
204 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
205 "10001",
206 "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
207 "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
208 );
209t1 = new Date().getTime();
210 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
211t2 = new Date().getTime();
212is("Encrypting with public key (2048)", (t2 - t1));
213
214 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 2048");
215t1 = new Date().getTime();
216 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 2048");
217t2 = new Date().getTime();
218is("Decrypting with private key (2048)", (t2 - t1));
219 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 2048");
220*/
221 }
222
223 //-------------------------------------------------------------------------
224 //
225 //Private key encryption -> Public key decryption
226 //
227 {
228 varcleanKey;
229 vart1, t2;
230/*
231 //
232 // 128
233 //
234 cleanKey = "248d6a61d20638b8e5c026930c3e6039"; //a33ce45964ff2167f6ecedd419db06c1";
235 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
236 "10001",
237 "202700adbd85e2d7182720c3a0ee19c1",
238 "30db31542ace0f7d37a629ee5eba28cb"
239 );
240 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
241
242 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 128");
243 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 128");
244 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 128");
245*/
246/*
247 //
248 // 256
249 //
250 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
251 cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
252 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
253 "10001",
254 "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
255 "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
256 );
257 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
258
259 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 256");
260 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 256");
261 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 256");
262*/
263/*
264 //
265 //512
266 //
267 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
268 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
269 "10001",
270 "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
271 "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
272 );
273t1 = new Date().getTime();
274 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
275t2 = new Date().getTime();
276//is("Encrypting with private key (512)", (t2 - t1));
277
278 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 512");
279t1 = new Date().getTime();
280 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 512");
281t2 = new Date().getTime();
282//is("Decrypting with public key (512)", (t2 - t1));
283 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 512");
284*/
285/*
286 //
287 //1024
288 //
289 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
290 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
291 "10001",
292 "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
293 "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
294 );
295t1 = new Date().getTime();
296 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
297t2 = new Date().getTime();
298is("Encrypting with private key (1024)", (t2 - t1));
299
300 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 1024");
301t1 = new Date().getTime();
302 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 1024");
303t2 = new Date().getTime();
304is("Decrypting with public key (1024)", (t2 - t1));
305 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 1024");
306*/
307/*
308 //
309 //2048
310 //
311 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
312 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
313 "10001",
314 "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
315 "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
316 );
317t1 = new Date().getTime();
318 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
319t2 = new Date().getTime();
320is("Encrypting with private key (2048)", (t2 - t1));
321
322 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 2048");
323t1 = new Date().getTime();
324 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 2048");
325t2 = new Date().getTime();
326is("Decrypting with public key (2048)", (t2 - t1));
327 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 2048");
328*/
329 }
330
331 varoriginalMessage;
332 varprocessedMessage;
333 var expectedResult;
334
335 //-------------------------------------------------------------------------
336 //
337 // HashSHA-256
338 //
339
340 originalMessage = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
341 expectedResult = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
342 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
343 is(processedMessage, expectedResult, "");
344
345 originalMessage = "";
346 expectedResult = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
347 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
348 is(processedMessage, expectedResult, "");
349
350 originalMessage = "abc";
351 expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
352 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
353 is(processedMessage, expectedResult, "");
354
355 originalMessage = "message digest";
356 expectedResult = "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
357 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
358 is(processedMessage, expectedResult, "");
359
360 originalMessage = "secure hash algorithm";
361 expectedResult = "f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d";
362 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
363 is(processedMessage, expectedResult, "");
364
365 originalMessage = "SHA256 is considered to be safe";
366 expectedResult = "6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630";
367 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
368 is(processedMessage, expectedResult, "");
369
370 originalMessage = "For this sample, this 63-byte string will be used as input data";
371 expectedResult = "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342";
372 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
373 is(processedMessage, expectedResult, "");
374
375 originalMessage = "This is exactly 64 bytes long, not counting the terminating byte";
376 expectedResult = "ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8";
377 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
378 is(processedMessage, expectedResult, "");
379
380 originalMessage = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut urna diam, vulputate quis, tempus vel, pretium in, mauris. Mauris aliquet sem a elit. Nunc molestie rutrum sem.";
381 expectedResult = "528059709af4087fb8cd4427e291d89f24d8c0429b2a3b6fd152c32ce5b4680f";
382 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
383 is(processedMessage, expectedResult, "");
384
385 //-------------------------------------------------------------------------
386 //
387 // HashMD5
388 //
389 originalMessage = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da9";
390 expectedResult = "fde790d7da7d0d54a8db4ac500f1bbdb";
391 processedMessage = Clipperz.Crypto.Base.computeMD5HashValue(originalMessage);
392 is(processedMessage, expectedResult, "");
393
394
395
396
397 //-------------------------------------------------------------------------
398 //
399 //Random seed
400 //
401 varrandomSeed;
402
403 randomSeed = Clipperz.Crypto.Base.generateRandomSeed();
404 is(randomSeed.length, 64, "");
405
406 ok(randomSeed != Clipperz.Crypto.Base.generateRandomSeed(), "");
407
408//#############################################################################
409
410} catch (err) {
411
412 var s = "test suite failure!\n";
413 var o = {};
414 var k = null;
415 for (k in err) {
416 // ensure unique keys?!
417 if (!o[k]) {
418 s += k + ": " + err[k] + "\n";
419 o[k] = err[k];
420 }
421 }
422 ok ( false, s );
423}
424
425</script>
426</pre>
427</body>
428</html>