Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/crypto/Cipher/TestGetInstance.java
41152 views
1
/*
2
* Copyright (c) 2003, 2008, 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 4898428
27
* @summary test that the new getInstance() implementation works correctly
28
* @author Andreas Sterbenz
29
*/
30
31
import java.security.*;
32
import java.security.spec.*;
33
34
import javax.crypto.*;
35
36
public class TestGetInstance {
37
38
private static void same(Provider p1, Provider p2) throws Exception {
39
if (p1 != p2) {
40
throw new Exception("not same object");
41
}
42
}
43
44
public static void main(String[] args) throws Exception {
45
Provider p = Security.getProvider("SunJCE");
46
47
Cipher c;
48
49
c = Cipher.getInstance("PBEWithMD5AndTripleDES");
50
same(p, c.getProvider());
51
52
c = Cipher.getInstance("des", "SunJCE");
53
same(p, c.getProvider());
54
c = Cipher.getInstance("des/cbc/pkcs5padding", "SunJCE");
55
same(p, c.getProvider());
56
57
c = Cipher.getInstance("des", p);
58
same(p, c.getProvider());
59
c = Cipher.getInstance("des/cbc/pkcs5padding", p);
60
same(p, c.getProvider());
61
62
try {
63
c = Cipher.getInstance("DES/XYZ/PKCS5Padding");
64
throw new AssertionError();
65
} catch (NoSuchAlgorithmException e) {
66
System.out.println(e);
67
}
68
try {
69
c = Cipher.getInstance("DES/XYZ/PKCS5Padding", "SunJCE");
70
throw new AssertionError();
71
} catch (NoSuchAlgorithmException e) {
72
System.out.println(e);
73
}
74
try {
75
c = Cipher.getInstance("DES/XYZ/PKCS5Padding", p);
76
throw new AssertionError();
77
} catch (NoSuchAlgorithmException e) {
78
System.out.println(e);
79
}
80
81
try {
82
c = Cipher.getInstance("DES/CBC/XYZPadding");
83
throw new AssertionError();
84
} catch (NoSuchAlgorithmException e) {
85
System.out.println(e);
86
}
87
try {
88
c = Cipher.getInstance("DES/CBC/XYZPadding", "SunJCE");
89
throw new AssertionError();
90
} catch (NoSuchPaddingException e) {
91
System.out.println(e);
92
}
93
try {
94
c = Cipher.getInstance("DES/CBC/XYZPadding", p);
95
throw new AssertionError();
96
} catch (NoSuchPaddingException e) {
97
System.out.println(e);
98
}
99
100
try {
101
c = Cipher.getInstance("foo");
102
throw new AssertionError();
103
} catch (NoSuchAlgorithmException e) {
104
System.out.println(e);
105
}
106
try {
107
c = Cipher.getInstance("foo", "SunJCE");
108
throw new AssertionError();
109
} catch (NoSuchAlgorithmException e) {
110
System.out.println(e);
111
}
112
try {
113
c = Cipher.getInstance("foo", p);
114
throw new AssertionError();
115
} catch (NoSuchAlgorithmException e) {
116
System.out.println(e);
117
}
118
119
try {
120
c = Cipher.getInstance("foo", "SUN");
121
throw new AssertionError();
122
} catch (NoSuchAlgorithmException e) {
123
System.out.println(e);
124
}
125
try {
126
c = Cipher.getInstance("foo", Security.getProvider("SUN"));
127
throw new AssertionError();
128
} catch (NoSuchAlgorithmException e) {
129
System.out.println(e);
130
}
131
try {
132
c = Cipher.getInstance("foo", "bar");
133
throw new AssertionError();
134
} catch (NoSuchProviderException e) {
135
System.out.println(e);
136
}
137
138
System.out.println("All Tests ok");
139
}
140
}
141
142