forked from kjur/jsrsasign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqunit-do-crypto-sigini.html
executable file
·337 lines (282 loc) · 12 KB
/
qunit-do-crypto-sigini.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for Signature.init() of 'crypto.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
// 1. DATA FOR PRIVATE KEY TEST
// 1.1. Plain PKCS#8 Private Key
// _test/z1.prv.p8p.pem (RSA)
var z1PrvP8PPEM = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA6GZN0rQFKRIVaPOz\n" +
"m8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJURX++I951D6uWxpO\n" +
"NRj9WQIDAQABAkB4u8VMZGeV6aYjyw+RLH+faGFxFWDle63iHe0vfZV5+GJy+rnn\n" +
"GrJygsJ2DEBNrmrIo6uFLPa81WL5r/gkeiZNAiEA/pvUUIZrMlVhT96XanasCx1Y\n" +
"MN2mT1NZuUbYUSvBI58CIQDpq2gPXwXbsPQxGw5vQ2j0h0oSOJedi8YAw1xvIHB8\n" +
"BwIhANVJy2mNwX1P4w5ahPOt6GADPB7rf2fShkZcn9gX1Fs3AiAYSbS7REk7mJ0J\n" +
"LaLGdd9G63kLg85eldSy55uIAXsvqQIgfSYaliVtSbAgyx1Yfs3hJ+CTpNKzTNv/\n" +
"Fx80EltYV6k=\n" +
"-----END PRIVATE KEY-----\n";
// _gitpg/jsrsasign/test/eckey/k1.prv.p8p.pem (ECC)
var k1PrvP8PPEM = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgEbVzfPnZPxfAyxqE\n" +
"ZV05laAoJAl+/6Xt2O4mOB611sOhRANCAASgFTKjwJAAU95g++/vzKWHkzAVmNMI\n" +
"tB5vTjZOOIwnEb70MsWZFIyUFD1P9Gwstz4+akHX7vI8BH6hHmBmfeQl\n" +
"-----END PRIVATE KEY-----\n";
// 1.2. Plain PKCS#5 Private Key
// _test/z1.prv.p5p.pem (RSA)
var z1PrvP5PPEM = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIBOgIBAAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4x\n" +
"EnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQJAeLvFTGRnlemmI8sPkSx/\n" +
"n2hhcRVg5Xut4h3tL32Vefhicvq55xqycoLCdgxATa5qyKOrhSz2vNVi+a/4JHom\n" +
"TQIhAP6b1FCGazJVYU/el2p2rAsdWDDdpk9TWblG2FErwSOfAiEA6atoD18F27D0\n" +
"MRsOb0No9IdKEjiXnYvGAMNcbyBwfAcCIQDVSctpjcF9T+MOWoTzrehgAzwe639n\n" +
"0oZGXJ/YF9RbNwIgGEm0u0RJO5idCS2ixnXfRut5C4POXpXUsuebiAF7L6kCIH0m\n" +
"GpYlbUmwIMsdWH7N4Sfgk6TSs0zb/xcfNBJbWFep\n" +
"-----END RSA PRIVATE KEY-----\n";
// 1.3. Encrypted PKCS#5 Private Key
// _test/z1.prv.p5e.pem (RSA)
var z1PrvPemP5E = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,4626F2E5853E783F\n" +
"\n" +
"3vFpkrnbantC8RSzng2+jBw/VX95oi0VGKP0G8whENHUOVQXB/YOUSj+n80Y0Wwc\n" +
"GpeQi8U0FQdWyYv8b9aioeFB06r9t9mJsYscJ/wcIvv5tTMkr89cwN3+4GQQuqNg\n" +
"TmI9ekeoZ3NP26hTM4XTuFqHx4dzNNwjDLc8txc77WE/o4J4p8k9Py5yPZjs9EKy\n" +
"wy/yxtqQYQuFj90OMEG1G89iHTZRcq4YTZYdqg6P/XEUvyjifN+7Nym8f2N9TDDn\n" +
"RJtApPQlrgXvUDQKz6Lu1ZYMwe94E9YdutDGQMbxixbiyxlcxrkb/oEHH5WP5qPG\n" +
"w/xzh08Ce2Ftba2Q860S8nznjyZFiv+lqSKBahbujgP/63ZL+JbAd4cYBqgm4g1C\n" +
"YwMhHJbaVCzwYduxdyK2JBYEosDZiDfnOP4DqPhJYpg=\n" +
"-----END RSA PRIVATE KEY-----\n";
var z1PrvPemP5EPass = "hoge";
// 1.4. Encrypted PKCS#8 Private Key
// _test/z1.prv.p8e.pem (RSA)
var z1PrvPemP8E = "" +
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
"MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIyScsGkpMl3kCAggA\n" +
"MBQGCCqGSIb3DQMHBAiObBK7oyBAzwSCAWCkStExnU3pYBQAxRqDctg5QEO3Ic1d\n" +
"GsRW+JW0kNonUydoOSD/7DBglnSDowiQ69HCW4OmumSJIU0hewX0yburFuy6Zs/q\n" +
"DkWox7oxBCsgFmfmkKGcK0USeJ+LX+YZVbvCCvHZkd99pEqQSfkRu4DgXbWmo6Zv\n" +
"2A6VFyBhE9MFmYex8mHTZ5cchBzAiFWRzjpRX94F4vbUFoXPGrEbOLovM2VpZ8Df\n" +
"1nLuXhWYVHsXHWn+fm7TH4Xzh1mFYYkTiXL9ABwKKohEL2SQJzKpa9FZvOZAmlSe\n" +
"UgQxVQLM/ZC+o4Vs4JHqIu4Ek2bgjEqDzo2EPznpcCsQTcwOqhPwNjP4Y3ovn1Nm\n" +
"8i0Hx51OA0vjRZBvvduKM9d5kRAOg8jqLjeWU3KraWLuSJ96RTzlWFgw6PsML+RE\n" +
"LHfdKDjRT0NMEMRh892oBi828asvvSWO6HYcM0xclt0uakxJhVP/mtzA\n" +
"-----END ENCRYPTED PRIVATE KEY-----\n";
var z1PrvPemP8EPass = "passwd";
// _gitpg/jsrsasign/test/eckey/k1.prv.p8e.pem pass:passwd
var k1PrvPemP8E = "" +
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
"MIHVMEAGCSqGSIb3DQEFDTAzMBsGCSqGSIb3DQEFDDAOBAj20JdDrZ2aywICCAAw\n" +
"FAYIKoZIhvcNAwcECMUYjGnyWlEZBIGQlK5TFonZXOFuu+UGi9VvH399ps4QHRe5\n" +
"ddRaWYUvjnKoA1kR8NorNzpAxwFeC0tGC9FHs8EV8gE1kCRJS0TBfn9Z3N/I+FEo\n" +
"s6qwahGeiHVJZQc6sHg8ch/At80D+2EpuQDhL/DYPYzDcxema7QE3gi0Q6rEuxgv\n" +
"1yqXRRTZGKyiNjmozXY/F0G6OQsT8BlA\n" +
"-----END ENCRYPTED PRIVATE KEY-----\n";
var k1PrvPemP8EPass = "passwd";
// 2. DATA FOR PUBLIC KEY TEST
// _test/z1 (RSA)
var z1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E\n" +
"8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQ==\n" +
"-----END PUBLIC KEY-----\n";
// _gitpg/jsrsasign/test/eckey/k1.pub.pem (ECC)
var k1PubPemP8 = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" +
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" +
"-----END PUBLIC KEY-----\n";
// _test/z1.cer (RSA)
var z1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIBdTCCAR+gAwIBAgIBBTANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL\n" +
"MAkGA1UECgwCYTEwHhcNMTMwNTA0MDM0MTQxWhcNMjMwNTA0MDM0MTQxWjAaMQsw\n" +
"CQYDVQQGEwJVUzELMAkGA1UECgwCYTEwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA\n" +
"6GZN0rQFKRIVaPOzm8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJ\n" +
"URX++I951D6uWxpONRj9WQIDAQABo1AwTjAdBgNVHQ4EFgQUxUc+4gDI561wA9/1\n" +
"QguM3fTCDhUwHwYDVR0jBBgwFoAUxUc+4gDI561wA9/1QguM3fTCDhUwDAYDVR0T\n" +
"BAUwAwEB/zANBgkqhkiG9w0BAQUFAANBALL2k69LjwOYfDXv3TXJUAFGUqto+Noj\n" +
"CJLP08fOfNBZy+KAIy0GsrNU/3uRViqbuGqAnH9kFFwHQjOAFrAe8XQ=\n" +
"-----END CERTIFICATE-----\n";
// _gitpg/jsrsasign/test/eckey/k1.self.cer
var k1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIBfDCCASGgAwIBAgIJAKbxELQvSUDNMAoGCCqGSM49BAMCMBoxCzAJBgNVBAYT\n" +
"AlVTMQswCQYDVQQKDAJLMTAeFw0xMzA3MTQwMjE3MTdaFw0yMzA3MTIwMjE3MTda\n" +
"MBoxCzAJBgNVBAYTAlVTMQswCQYDVQQKDAJLMTBZMBMGByqGSM49AgEGCCqGSM49\n" +
"AwEHA0IABKAVMqPAkABT3mD77+/MpYeTMBWY0wi0Hm9ONk44jCcRvvQyxZkUjJQU\n" +
"PU/0bCy3Pj5qQdfu8jwEfqEeYGZ95CWjUDBOMB0GA1UdDgQWBBTIR74yfMz/Y4hw\n" +
"dXSW4r42bESo/DAfBgNVHSMEGDAWgBTIR74yfMz/Y4hwdXSW4r42bESo/DAMBgNV\n" +
"HRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDfAcS/WKBrP6JBgksQVpp4jdq4\n" +
"C53Yu4F5NkaMgthAHgIhANGRdWAP1QdW9l6tiglQwdqJs4T0e8+NYv+RcAb3VYwn\n" +
"-----END CERTIFICATE-----\n";
// 3. Priavte Key Test
// 3.1. Plain PKCS#8 Private Key Test (RSA,ECC)
test("sign init plain PKCS#8 Private Key PEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1PrvP8PPEM);
equal(sig.state, "SIGN");
});
test("sign init plain PKCS#8 Private Key PEM(ECC)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig.init(k1PrvP8PPEM);
equal(sig.state, "SIGN");
});
// 3.2. Plain PKCS#5 Private Key Test (RSA)
test("sign init plain PKCS#5 Privae Key PEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1PrvP5PPEM);
equal(sig.state, "SIGN");
});
// 3.3. Encrypted PKCS#5 Private Key Test (RSA)
test("sign init encrypted PKCS#5 Privae Key PEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1PrvPemP5E, z1PrvPemP5EPass);
equal(sig.state, "SIGN");
});
// 3.4. Encrypted PKCS#8 Private Key Test (RSA,ECC)
test("sign init encrypted PKCS#8 Privae Key PEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1PrvPemP8E, z1PrvPemP8EPass);
equal(sig.state, "SIGN");
});
test("sign init encrypted PKCS#8 Privae Key PEM(ECC) pretest(key loading)", function() {
var key = KEYUTIL.getKey(k1PrvPemP8E, k1PrvPemP8EPass);
expect(2);
equal(key.type, "EC", "type");
ok(key.isPrivate, "isPrivate");
});
test("sign init encrypted PKCS#8 Privae Key PEM(ECC)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig.init(k1PrvPemP8E, k1PrvPemP8EPass);
equal(sig.state, "SIGN");
});
// 4. Public Key Test
// PKCS#8 Public Key Test (RSA,ECC)
test("verify init PKCS#8 Public Key PEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1PubPemP8);
equal(sig.state, "VERIFY");
});
test("verify init PKCS#8 Public Key PEM(ECC)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig.init(k1PubPemP8);
equal(sig.state, "VERIFY");
});
// Certificate Test (RSA,ECC)
test("verify init CertPEM(RSA)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(z1CertPEM);
equal(sig.state, "VERIFY");
});
test("verify init CertPEM(ECC)", function() {
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig.init(k1CertPEM);
equal(sig.state, "VERIFY");
});
// Public Key Object Test (RSA,ECC)
test("verify init key object(RSA)", function() {
var pubKey = X509.getPublicKeyFromCertPEM(z1CertPEM);
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig.init(pubKey);
equal(sig.state, "VERIFY");
});
test("verify init key object(ECC)", function() {
var pubKey = X509.getPublicKeyFromCertPEM(k1CertPEM);
var sig = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig.init(pubKey);
equal(sig.state, "VERIFY");
});
// 5. Sign and Verify Integrated Test
test("sign and verify integrated test (RSA)", function() {
var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig1.init(z1PrvP8PPEM);
sig1.updateString("aaa");
var hSigVal = sig1.sign();
var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withRSA'});
sig2.init(z1CertPEM);
sig2.updateString("aaa");
equal(sig2.verify(hSigVal), true, "t1");
});
test("sign and verify integrated test (ECC)", function() {
var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig1.init(k1PrvP8PPEM);
sig1.updateString("aaa");
var hSigVal = sig1.sign();
var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withECDSA'});
sig2.init(k1CertPEM);
sig2.updateString("aaa");
equal(sig2.verify(hSigVal), true, "t1");
});
test("sign and verify integrated test (RSAPSS)", function() {
var sig1 = new KJUR.crypto.Signature({'alg': 'SHA1withRSAandMGF1'});
sig1.init(z1PrvP8PPEM);
sig1.updateString("aaa");
var hSigVal = sig1.sign();
var sig2 = new KJUR.crypto.Signature({'alg': 'SHA1withRSAandMGF1'});
sig2.init(z1CertPEM);
sig2.updateString("aaa");
equal(sig2.verify(hSigVal), true, "t1");
});
});
-->
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
ECC related QUnit test pages:
<a href="qunit-do-crypto.html">crypto.js</a> |
<a href="qunit-do-crypto-ecdsa.html">crypto.js Signature class for ECDSA</a> |
<a href="qunit-do-ecdsamod.html">ecdsa-modified.js</a> |
<a href="qunit-do-ecparam.html">ecparam.js</a> |
</p>
</body>
</html>