Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/mscapi/KeyAlgorithms.java
41149 views
1
/*
2
* Copyright (c) 2018, 2020, 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
/**
25
* @test
26
* @bug 8213009 8237804
27
* @summary Make sure SunMSCAPI keys have correct algorithm names
28
* @requires os.family == "windows"
29
* @library /test/lib
30
* @modules jdk.crypto.mscapi
31
*/
32
33
import java.security.*;
34
35
import jdk.test.lib.Asserts;
36
import jdk.test.lib.SecurityTools;
37
38
public class KeyAlgorithms {
39
40
private static final String ALIAS = "8213009";
41
private static final String ALG = "RSA";
42
43
public static void main(String[] arg) throws Exception {
44
45
cleanup();
46
SecurityTools.keytool("-genkeypair",
47
"-storetype", "Windows-My",
48
"-keyalg", ALG,
49
"-alias", ALIAS,
50
"-dname", "cn=" + ALIAS,
51
"-noprompt").shouldHaveExitValue(0);
52
53
try {
54
test(loadKeysFromKeyStore());
55
} finally {
56
cleanup();
57
}
58
59
test(generateKeys());
60
}
61
62
private static void cleanup() {
63
try {
64
KeyStore ks = KeyStore.getInstance("Windows-MY");
65
ks.load(null, null);
66
ks.deleteEntry(ALIAS);
67
ks.store(null, null);
68
} catch (Exception e) {
69
System.out.println("No such entry.");
70
}
71
}
72
73
static KeyPair loadKeysFromKeyStore() throws Exception {
74
KeyStore ks = KeyStore.getInstance("Windows-MY");
75
ks.load(null, null);
76
return new KeyPair(ks.getCertificate(ALIAS).getPublicKey(),
77
(PrivateKey) ks.getKey(ALIAS, null));
78
}
79
80
static KeyPair generateKeys() throws Exception {
81
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALG, "SunMSCAPI");
82
return kpg.generateKeyPair();
83
}
84
85
static void test(KeyPair kp) {
86
Asserts.assertEQ(kp.getPrivate().getAlgorithm(), ALG);
87
Asserts.assertEQ(kp.getPublic().getAlgorithm(), ALG);
88
}
89
}
90
91