summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
Side-by-side diff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/Base.html') (more/less context) (ignore 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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ var secretKey;
+ var publicKey;
+ var plainString;
+ var encryptedString;
+
+
+ secretKey = "s3cr37k39";
+ plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+
+ //-------------------------------------------------------------------------
+ //
+ // Secret key encryption / decryption
+ //
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string should not be empty");
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ try {
+ var decryptedText;
+
+ decryptedText = Clipperz.Crypto.Base.decryptUsingSecretKey("anotherKey", encryptedString);
+ ok( false, "It should not be possible to decrypt a text with a different passphrase (decrypted text: " + decryptedText + ")" );
+ } catch (e) {
+ ok( e instanceof Error, "Trying to decrypt a message with the wrong passphrase raised an error" );
+ }
+
+ is (encryptedString == Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString), false, "Two consecutive encryption of the same text should return different values");
+
+ secretKey = "trustno1";
+ plainString = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ secretKey = "trustno1";
+ 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.";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ secretKey = "trustno1";
+ 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";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+// secretKey = "trustno1";
+// plainString = "{}";
+// 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'}}} ";
+// plainString = "{'tags': {}, 'records': {'07a5a92fcb334f757998ba14f3251f126d038318b3ac5e584bd712804c548084': {'label': 'Un bel record', 'key': '2a3f261c20a6a98dcc82b13fba013130b759f20602b4b13c5760879e087482a4'}}}";
+// encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+// is(encryptedString, "{}", "encrypted value");
+
+
+// secretKey = "trustno1";
+// encryptedString = "0d43a4544424ffa519f2e43b7a46f703884fd94ff9879479563f6f252a573b253d3e77bc4f5f30f17bd11d2907718921ab8c9e1faccbe4314793fa323eb85eaf1bfbce5f7deea601e15b781782181cbff3c649dafef39abb70e8573e4f9be220f2286b01c3bd51d5c4a79b9d44a27be3b0994667302e301ca3dc074fb1bc7abc03d12b9e58ba0249435a120858c96e8ae99570718541499ab958a8fb92b63390be070ff61fc6ef107061693ab14c1915118cc6671ab7cf99b9cca553d6b5a7c314bffcd933e0a59f056d842a47cfe8571110b4764c5225443210d99b43b80a23c20fe953de3e1329d72cfb20139fe1ca";
+// plainString = Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString);
+// is(plainString, "{}", "decrypted value");
+
+ //-------------------------------------------------------------------------
+ //
+ // Java secret key encryption / JavaScript decryption
+ //
+ secretKey = "s3cr37k39";
+ plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
+ encryptedString = "9be538c3dde4dfab9384c0ef71dc624299fbbe71be8d1fe8991fd6cae88a883cf459d7cd56913a2b69815782cf74d7ce5c2c08034661f7f8aa59cf420e913086896840ebb45102d44d733d32de2a7dc8";
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ //-------------------------------------------------------------------------
+ //
+ // Public key encryption -> Private key decryption
+ //
+ {
+ var cleanKey;
+ var t1, t2;
+/*
+ //
+ // 128
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039"; // a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "202700adbd85e2d7182720c3a0ee19c1",
+ "30db31542ace0f7d37a629ee5eba28cb"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 128");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 128");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 128");
+*/
+/*
+ //
+ // 256
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
+ "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 256");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 256");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 256");
+*/
+/*
+ //
+ // 512
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
+ "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+//is("Encrypting with public key (512)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 512");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 512");
+t2 = new Date().getTime();
+//is("Decrypting with private key (512)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 512");
+*/
+/*
+ //
+ // 1024
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
+ "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with public key (1024)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 1024");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 1024");
+t2 = new Date().getTime();
+is("Decrypting with private key (1024)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 1024");
+*/
+/*
+ //
+ // 2048
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
+ "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with public key (2048)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 2048");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 2048");
+t2 = new Date().getTime();
+is("Decrypting with private key (2048)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 2048");
+*/
+ }
+
+ //-------------------------------------------------------------------------
+ //
+ // Private key encryption -> Public key decryption
+ //
+ {
+ var cleanKey;
+ var t1, t2;
+/*
+ //
+ // 128
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039"; // a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "202700adbd85e2d7182720c3a0ee19c1",
+ "30db31542ace0f7d37a629ee5eba28cb"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 128");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 128");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 128");
+*/
+/*
+ //
+ // 256
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
+ "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 256");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 256");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 256");
+*/
+/*
+ //
+ // 512
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
+ "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+//is("Encrypting with private key (512)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 512");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 512");
+t2 = new Date().getTime();
+//is("Decrypting with public key (512)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 512");
+*/
+/*
+ //
+ // 1024
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
+ "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with private key (1024)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 1024");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 1024");
+t2 = new Date().getTime();
+is("Decrypting with public key (1024)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 1024");
+*/
+/*
+ //
+ // 2048
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
+ "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with private key (2048)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 2048");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 2048");
+t2 = new Date().getTime();
+is("Decrypting with public key (2048)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 2048");
+*/
+ }
+
+ var originalMessage;
+ var processedMessage;
+ var expectedResult;
+
+ //-------------------------------------------------------------------------
+ //
+ // Hash SHA-256
+ //
+
+ originalMessage = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+ expectedResult = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "";
+ expectedResult = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "abc";
+ expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "message digest";
+ expectedResult = "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "secure hash algorithm";
+ expectedResult = "f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "SHA256 is considered to be safe";
+ expectedResult = "6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "For this sample, this 63-byte string will be used as input data";
+ expectedResult = "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "This is exactly 64 bytes long, not counting the terminating byte";
+ expectedResult = "ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ 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.";
+ expectedResult = "528059709af4087fb8cd4427e291d89f24d8c0429b2a3b6fd152c32ce5b4680f";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ //-------------------------------------------------------------------------
+ //
+ // Hash MD5
+ //
+ originalMessage = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da9";
+ expectedResult = "fde790d7da7d0d54a8db4ac500f1bbdb";
+ processedMessage = Clipperz.Crypto.Base.computeMD5HashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+
+
+
+ //-------------------------------------------------------------------------
+ //
+ // Random seed
+ //
+ var randomSeed;
+
+ randomSeed = Clipperz.Crypto.Base.generateRandomSeed();
+ is(randomSeed.length, 64, "");
+
+ ok(randomSeed != Clipperz.Crypto.Base.generateRandomSeed(), "");
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</html>