1 /*
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
41 Provider[] providers = Security.getProviders("Signature.SHA256withRSA");
42 if (providers == null) {
43 System.out.println("No JCE providers support the " +
44 "'Signature.SHA256withRSA' algorithm");
45 System.out.println("Skipping this test...");
46 return;
47
48 } else {
49 System.out.println("The following JCE providers support the " +
50 "'Signature.SHA256withRSA' algorithm: ");
51 for (Provider provider : providers) {
52 System.out.println(" " + provider.getName());
53 }
54 }
55 System.out.println("-------------------------------------------------");
56
57 KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
58 ks.load(null, null);
59 System.out.println("Loaded keystore: Windows-MY");
60
61 Enumeration e = ks.aliases();
62 PrivateKey privateKey = null;
63 PublicKey publicKey = null;
64
65 while (e.hasMoreElements()) {
66 String alias = (String) e.nextElement();
67 if (alias.equals("6753664")) {
68 System.out.println("Loaded entry: " + alias);
69 privateKey = (PrivateKey) ks.getKey(alias, null);
70 publicKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
71 }
72 }
73 if (privateKey == null || publicKey == null) {
74 throw new Exception("Cannot load the keys need to run this test");
75 }
76 System.out.println("-------------------------------------------------");
77
78 generatedSignatures.add(signUsing("SHA256withRSA", privateKey));
79 generatedSignatures.add(signUsing("SHA384withRSA", privateKey));
80 generatedSignatures.add(signUsing("SHA512withRSA", privateKey));
81
82 System.out.println("-------------------------------------------------");
83
84 verifyUsing("SHA256withRSA", publicKey, generatedSignatures.get(0));
85 verifyUsing("SHA384withRSA", publicKey, generatedSignatures.get(1));
86 verifyUsing("SHA512withRSA", publicKey, generatedSignatures.get(2));
|
1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
41 Provider[] providers = Security.getProviders("Signature.SHA256withRSA");
42 if (providers == null) {
43 System.out.println("No JCE providers support the " +
44 "'Signature.SHA256withRSA' algorithm");
45 System.out.println("Skipping this test...");
46 return;
47
48 } else {
49 System.out.println("The following JCE providers support the " +
50 "'Signature.SHA256withRSA' algorithm: ");
51 for (Provider provider : providers) {
52 System.out.println(" " + provider.getName());
53 }
54 }
55 System.out.println("-------------------------------------------------");
56
57 KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
58 ks.load(null, null);
59 System.out.println("Loaded keystore: Windows-MY");
60
61 Enumeration<String> e = ks.aliases();
62 PrivateKey privateKey = null;
63 PublicKey publicKey = null;
64
65 while (e.hasMoreElements()) {
66 String alias = e.nextElement();
67 if (alias.equals("6753664")) {
68 System.out.println("Loaded entry: " + alias);
69 privateKey = (PrivateKey) ks.getKey(alias, null);
70 publicKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
71 }
72 }
73 if (privateKey == null || publicKey == null) {
74 throw new Exception("Cannot load the keys need to run this test");
75 }
76 System.out.println("-------------------------------------------------");
77
78 generatedSignatures.add(signUsing("SHA256withRSA", privateKey));
79 generatedSignatures.add(signUsing("SHA384withRSA", privateKey));
80 generatedSignatures.add(signUsing("SHA512withRSA", privateKey));
81
82 System.out.println("-------------------------------------------------");
83
84 verifyUsing("SHA256withRSA", publicKey, generatedSignatures.get(0));
85 verifyUsing("SHA384withRSA", publicKey, generatedSignatures.get(1));
86 verifyUsing("SHA512withRSA", publicKey, generatedSignatures.get(2));
|