Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/pkcs11/Signature/TestDSA2.java
38855 views
1
/*
2
* Copyright (c) 2012, 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
*/
23
/*
24
* @test
25
* @bug 8080462
26
* @library ..
27
* @modules jdk.crypto.cryptoki
28
* @run main/othervm/timeout=250 TestDSA2
29
* @summary verify that DSA signature works using SHA-2 digests.
30
* @key randomness
31
*/
32
33
34
import java.security.*;
35
import java.security.spec.*;
36
import java.security.interfaces.*;
37
38
public class TestDSA2 extends PKCS11Test {
39
40
private static final String[] SIG_ALGOS = {
41
"SHA224withDSA",
42
"SHA256withDSA",
43
//"SHA384withDSA",
44
//"SHA512withDSA",
45
};
46
47
private static final int KEYSIZE = 2048;
48
49
public static void main(String[] args) throws Exception {
50
main(new TestDSA2(), args);
51
}
52
53
@Override
54
public void main(Provider p) throws Exception {
55
KeyPair kp;
56
try {
57
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA", p);
58
kpg.initialize(KEYSIZE);
59
kp = kpg.generateKeyPair();
60
} catch (Exception ex) {
61
System.out.println("Skip due to no 2048-bit DSA support: " + ex);
62
ex.printStackTrace();
63
return;
64
}
65
66
for (String sigAlg : SIG_ALGOS) {
67
test(sigAlg, kp, p);
68
}
69
}
70
71
private static void test(String sigAlg, KeyPair kp, Provider p)
72
throws Exception {
73
Signature sig;
74
try {
75
sig = Signature.getInstance(sigAlg, p);
76
} catch (Exception ex) {
77
System.out.println("Skip due to no support: " + sigAlg);
78
ex.printStackTrace();
79
return;
80
}
81
82
byte[] data = "anything will do".getBytes();
83
84
sig.initSign(kp.getPrivate());
85
sig.update(data);
86
byte[] signature = sig.sign();
87
88
sig.initVerify(kp.getPublic());
89
sig.update(data);
90
boolean verifies = sig.verify(signature);
91
System.out.println(sigAlg + ": Passed");
92
}
93
}
94
95