Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html b/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html index 63f7610..8920915 100644 --- a/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html | |||
@@ -1,120 +1,117 @@ | |||
1 | <!-- | 1 | <!-- |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | it and/or modify it under the terms of the GNU Affero General Public | 11 | 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 | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | --> | 24 | --> |
28 | 25 | ||
29 | <html> | 26 | <html> |
30 | <head> | 27 | <head> |
31 | <title>Clipperz.Crypto.Usage - TEST</title> | 28 | <title>Clipperz.Crypto.Usage - TEST</title> |
32 | 29 | ||
33 | <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> | 30 | <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> |
34 | <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script> | 31 | <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script> |
35 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> | 32 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> |
36 | <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> | 33 | <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> |
37 | 34 | ||
38 | <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> | 35 | <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> |
39 | 36 | ||
40 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> | 37 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> |
41 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> | 38 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> |
42 | <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> | 39 | <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> |
43 | <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> | 40 | <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> |
44 | <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> | 41 | <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> |
45 | 42 | ||
46 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> | 43 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> |
47 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> | 44 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> |
48 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> | 45 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> |
49 | 46 | ||
50 | </head> | 47 | </head> |
51 | <body> | 48 | <body> |
52 | <pre id="test"> | 49 | <pre id="test"> |
53 | <script type="text/javascript"> | 50 | <script type="text/javascript"> |
54 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); | 51 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); |
55 | 52 | ||
56 | MochiKit.Base.update(Clipperz, { | 53 | MochiKit.Base.update(Clipperz, { |
57 | 'PM': { | 54 | 'PM': { |
58 | 'Crypto': { | 55 | 'Crypto': { |
59 | 'passwordEntropy': function(aValue) { | 56 | 'passwordEntropy': function(aValue) { |
60 | var result; | 57 | var result; |
61 | varbitPerChar; | 58 | varbitPerChar; |
62 | 59 | ||
63 | bitPerChar = 4; | 60 | bitPerChar = 4; |
64 | if (/[a-z]/.test(aValue)) { | 61 | if (/[a-z]/.test(aValue)) { |
65 | bitPerChar ++; | 62 | bitPerChar ++; |
66 | } | 63 | } |
67 | if (/[A-Z]/.test(aValue)) { | 64 | if (/[A-Z]/.test(aValue)) { |
68 | bitPerChar ++; | 65 | bitPerChar ++; |
69 | } | 66 | } |
70 | if (/[^a-zA-Z0-9]/.test(aValue)) { | 67 | if (/[^a-zA-Z0-9]/.test(aValue)) { |
71 | bitPerChar ++; | 68 | bitPerChar ++; |
72 | } | 69 | } |
73 | //MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar); | 70 | //MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar); |
74 | 71 | ||
75 | result = aValue.length * bitPerChar; | 72 | result = aValue.length * bitPerChar; |
76 | 73 | ||
77 | return result; | 74 | return result; |
78 | } | 75 | } |
79 | } | 76 | } |
80 | } | 77 | } |
81 | }) | 78 | }) |
82 | 79 | ||
83 | try { | 80 | try { |
84 | var keyValue; | 81 | var keyValue; |
85 | var keyEntropy; | 82 | var keyEntropy; |
86 | varkey; | 83 | varkey; |
87 | var plainText; | 84 | var plainText; |
88 | var cypherText; | 85 | var cypherText; |
89 | var randomBytes; | 86 | var randomBytes; |
90 | var hashedValue; | 87 | var hashedValue; |
91 | 88 | ||
92 | key = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("This is my long and complex passphrase")); | 89 | key = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("This is my long and complex passphrase")); |
93 | keyEntropy = Clipperz.PM.Crypto.passwordEntropy(key); | 90 | keyEntropy = Clipperz.PM.Crypto.passwordEntropy(key); |
94 | 91 | ||
95 | cypherText = Clipperz.Crypto.AES.encrypt(key, new Clipperz.ByteArray("some text to encrypt")); | 92 | cypherText = Clipperz.Crypto.AES.encrypt(key, new Clipperz.ByteArray("some text to encrypt")); |
96 | plainText = Clipperz.Crypto.AES.decrypt(key, cypherText).asString(); | 93 | plainText = Clipperz.Crypto.AES.decrypt(key, cypherText).asString(); |
97 | is(plainText, "some text to encrypt"); | 94 | is(plainText, "some text to encrypt"); |
98 | 95 | ||
99 | randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(256/8); | 96 | randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(256/8); |
100 | hashedValue = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("text to hash")); | 97 | hashedValue = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("text to hash")); |
101 | 98 | ||
102 | //############################################################################# | 99 | //############################################################################# |
103 | 100 | ||
104 | } catch (err) { | 101 | } catch (err) { |
105 | 102 | ||
106 | var s = "test suite failure!\n"; | 103 | var s = "test suite failure!\n"; |
107 | var o = {}; | 104 | var o = {}; |
108 | var k = null; | 105 | var k = null; |
109 | for (k in err) { | 106 | for (k in err) { |
110 | // ensure unique keys?! | 107 | // ensure unique keys?! |
111 | if (!o[k]) { | 108 | if (!o[k]) { |
112 | s += k + ": " + err[k] + "\n"; | 109 | s += k + ": " + err[k] + "\n"; |
113 | o[k] = err[k]; | 110 | o[k] = err[k]; |
114 | } | 111 | } |
115 | } | 112 | } |
116 | ok ( false, s ); | 113 | ok ( false, s ); |
117 | } | 114 | } |
118 | 115 | ||
119 | </script> | 116 | </script> |
120 | </pre> | 117 | </pre> |