Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyFactory.java
41155 views
1
/*
2
* Copyright (c) 1998, 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
/*
25
* @test
26
* @bug 0000000
27
* @summary DHKeyFactory
28
* @author Jan Luehe
29
*/
30
31
import java.io.*;
32
import java.math.BigInteger;
33
import java.security.*;
34
import java.security.spec.*;
35
import java.security.interfaces.*;
36
import javax.crypto.*;
37
import javax.crypto.spec.*;
38
import javax.crypto.interfaces.*;
39
40
/**
41
* This test creates a DH keypair, retrieves the encodings of the DH public and
42
* private key, and feeds those encodings to a DH key factory, which parses
43
* the encodings and creates a DH public and private key from them.
44
*/
45
46
public class DHKeyFactory {
47
48
private DHKeyFactory() {}
49
50
public static void main(String argv[]) throws Exception {
51
DHKeyFactory test = new DHKeyFactory();
52
test.run();
53
System.out.println("Test Passed");
54
}
55
56
private void run() throws Exception {
57
58
DHParameterSpec dhSkipParamSpec;
59
60
// use some pre-generated, default DH parameters
61
System.err.println("Using SKIP Diffie-Hellman parameters");
62
dhSkipParamSpec = new DHParameterSpec(skip1024Modulus,
63
skip1024Base);
64
65
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DH", "SunJCE");
66
kpgen.initialize(dhSkipParamSpec);
67
KeyPair kp = kpgen.generateKeyPair();
68
69
// get the public key encoding
70
byte[] pubKeyEnc = kp.getPublic().getEncoded();
71
72
// get the private key encoding
73
byte[] privKeyEnc = kp.getPrivate().getEncoded();
74
75
KeyFactory kfac = KeyFactory.getInstance("DH", "SunJCE");
76
77
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKeyEnc);
78
PublicKey pubKey = kfac.generatePublic(x509KeySpec);
79
80
PKCS8EncodedKeySpec pkcsKeySpec = new PKCS8EncodedKeySpec(privKeyEnc);
81
PrivateKey privKey = kfac.generatePrivate(pkcsKeySpec);
82
}
83
84
// The 1024 bit Diffie-Hellman modulus values used by SKIP
85
private static final byte skip1024ModulusBytes[] = {
86
(byte)0xF4, (byte)0x88, (byte)0xFD, (byte)0x58,
87
(byte)0x4E, (byte)0x49, (byte)0xDB, (byte)0xCD,
88
(byte)0x20, (byte)0xB4, (byte)0x9D, (byte)0xE4,
89
(byte)0x91, (byte)0x07, (byte)0x36, (byte)0x6B,
90
(byte)0x33, (byte)0x6C, (byte)0x38, (byte)0x0D,
91
(byte)0x45, (byte)0x1D, (byte)0x0F, (byte)0x7C,
92
(byte)0x88, (byte)0xB3, (byte)0x1C, (byte)0x7C,
93
(byte)0x5B, (byte)0x2D, (byte)0x8E, (byte)0xF6,
94
(byte)0xF3, (byte)0xC9, (byte)0x23, (byte)0xC0,
95
(byte)0x43, (byte)0xF0, (byte)0xA5, (byte)0x5B,
96
(byte)0x18, (byte)0x8D, (byte)0x8E, (byte)0xBB,
97
(byte)0x55, (byte)0x8C, (byte)0xB8, (byte)0x5D,
98
(byte)0x38, (byte)0xD3, (byte)0x34, (byte)0xFD,
99
(byte)0x7C, (byte)0x17, (byte)0x57, (byte)0x43,
100
(byte)0xA3, (byte)0x1D, (byte)0x18, (byte)0x6C,
101
(byte)0xDE, (byte)0x33, (byte)0x21, (byte)0x2C,
102
(byte)0xB5, (byte)0x2A, (byte)0xFF, (byte)0x3C,
103
(byte)0xE1, (byte)0xB1, (byte)0x29, (byte)0x40,
104
(byte)0x18, (byte)0x11, (byte)0x8D, (byte)0x7C,
105
(byte)0x84, (byte)0xA7, (byte)0x0A, (byte)0x72,
106
(byte)0xD6, (byte)0x86, (byte)0xC4, (byte)0x03,
107
(byte)0x19, (byte)0xC8, (byte)0x07, (byte)0x29,
108
(byte)0x7A, (byte)0xCA, (byte)0x95, (byte)0x0C,
109
(byte)0xD9, (byte)0x96, (byte)0x9F, (byte)0xAB,
110
(byte)0xD0, (byte)0x0A, (byte)0x50, (byte)0x9B,
111
(byte)0x02, (byte)0x46, (byte)0xD3, (byte)0x08,
112
(byte)0x3D, (byte)0x66, (byte)0xA4, (byte)0x5D,
113
(byte)0x41, (byte)0x9F, (byte)0x9C, (byte)0x7C,
114
(byte)0xBD, (byte)0x89, (byte)0x4B, (byte)0x22,
115
(byte)0x19, (byte)0x26, (byte)0xBA, (byte)0xAB,
116
(byte)0xA2, (byte)0x5E, (byte)0xC3, (byte)0x55,
117
(byte)0xE9, (byte)0x2F, (byte)0x78, (byte)0xC7
118
};
119
120
// The SKIP 1024 bit modulus
121
private static final BigInteger skip1024Modulus
122
= new BigInteger(1, skip1024ModulusBytes);
123
124
// The base used with the SKIP 1024 bit modulus
125
private static final BigInteger skip1024Base = BigInteger.valueOf(2);
126
}
127
128