Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/Cipher/DES/Sealtest.java
41161 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 7055362
27
* @summary Sealtest
28
* @author Jan Luehe
29
*/
30
import java.io.*;
31
import java.security.*;
32
import javax.crypto.*;
33
34
public class Sealtest {
35
36
public static void main(String[] args) throws Exception {
37
38
// create DSA keypair
39
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DSA");
40
kpgen.initialize(512);
41
KeyPair kp = kpgen.generateKeyPair();
42
43
// create DES key
44
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
45
SecretKey skey = kg.generateKey();
46
47
// create cipher
48
Cipher c = Cipher.getInstance("DES/CFB16/PKCS5Padding", "SunJCE");
49
c.init(Cipher.ENCRYPT_MODE, skey);
50
51
// seal the DSA private key
52
SealedObject sealed = new SealedObject(kp.getPrivate(), c);
53
54
// serialize
55
try (FileOutputStream fos = new FileOutputStream("sealed");
56
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
57
oos.writeObject(sealed);
58
}
59
60
// deserialize
61
try (FileInputStream fis = new FileInputStream("sealed");
62
ObjectInputStream ois = new ObjectInputStream(fis)) {
63
sealed = (SealedObject)ois.readObject();
64
}
65
66
System.out.println(sealed.getAlgorithm());
67
68
// compare unsealed private key with original
69
PrivateKey priv = (PrivateKey)sealed.getObject(skey);
70
if (!priv.equals(kp.getPrivate()))
71
throw new Exception("TEST FAILED");
72
73
System.out.println("TEST SUCCEEDED");
74
}
75
}
76
77