blob: 029a5b95b1677bef8bab76e13cd67e57a079ef53 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 6329006
27 * @summary verify that NSS no-db mode works correctly
28 * @author Andreas Sterbenz
29 * @library ..
30 */
31
32import java.util.*;
33
34import java.security.*;
35
36public class Crypto extends SecmodTest {
37
38 public static void main(String[] args) throws Exception {
39 if (initSecmod() == false) {
40 return;
41 }
42
43 String configName = BASE + SEP + "nsscrypto.cfg";
44 Provider p = getSunPKCS11(configName);
45
46 KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", p);
47 KeyPair kp = kpg.generateKeyPair();
48
49 System.out.println(kp.getPublic());
50 System.out.println(kp.getPrivate());
51
52 SecureRandom random = new SecureRandom();
53 byte[] data = new byte[2048];
54 random.nextBytes(data);
55
56 Signature sig = Signature.getInstance("SHA1withRSA", p);
57 sig.initSign(kp.getPrivate());
58
59 sig.update(data);
60 byte[] s = sig.sign();
61 System.out.println("signature: " + toString(s));
62
63 sig.initVerify(kp.getPublic());
64 sig.update(data);
65 boolean ok = sig.verify(s);
66 if (ok == false) {
67 throw new Exception("Signature verification failed");
68 }
69
70 System.out.println("OK");
71 }
72
73}