Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs11/Cipher/Test4512704.java
41152 views
1
/*
2
* Copyright (c) 2018, 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 8080462
27
* @library /test/lib ..
28
* @modules jdk.crypto.cryptoki
29
* @run main Test4512704
30
* @summary Verify that AES cipher can generate default IV in encrypt mode
31
*/
32
import java.io.PrintStream;
33
import java.security.*;
34
import java.security.spec.*;
35
import java.util.Random;
36
37
import javax.crypto.*;
38
import javax.crypto.spec.*;
39
import java.security.Provider;
40
41
public class Test4512704 extends PKCS11Test {
42
43
public void test(String mode, Provider p) throws Exception {
44
Cipher c;
45
String transformation = "AES/" + mode + "/NoPadding";
46
47
try {
48
transformation = "AES/" + mode + "/NoPadding";
49
c = Cipher.getInstance(transformation, p);
50
} catch (GeneralSecurityException e) {
51
System.out.println("Skip testing " + p.getName() +
52
", no support for " + mode);
53
return;
54
}
55
SecretKey key = new SecretKeySpec(new byte[16], "AES");
56
57
AlgorithmParameterSpec aps = null;
58
Cipher ci = Cipher.getInstance(transformation, p);
59
try {
60
ci.init(Cipher.ENCRYPT_MODE, key, aps);
61
} catch(InvalidAlgorithmParameterException ex) {
62
throw new Exception("parameter should be generated when null is specified!");
63
}
64
System.out.println(transformation + ": Passed");
65
}
66
67
public static void main (String[] args) throws Exception {
68
main(new Test4512704(), args);
69
}
70
71
@Override
72
public void main(Provider p) throws Exception {
73
test("GCM", p);
74
}
75
76
}
77
78