Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/CICO/PBEFunc/AbstractPBEWrapper.java
41161 views
1
/*
2
* Copyright (c) 2007, 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
import java.security.GeneralSecurityException;
24
import javax.crypto.Cipher;
25
26
/**
27
* PBEWrapper is an abstract class for all concrete PBE Cipher wrappers.
28
*/
29
public abstract class AbstractPBEWrapper {
30
/**
31
* Iteration count.
32
*/
33
public static final int DEFAULT_ITERATION = 1000;
34
35
public static final String PBKDF2 = "PBKDF2";
36
public static final String AES = "AES";
37
public static final String DEFAULT = "default";
38
39
/**
40
* transformation the name of the transformation, e.g.,
41
* DES/CBC/PKCS5Padding
42
*/
43
protected final String transformation;
44
45
/**
46
* the standard name of the requested secret-key algorithm.
47
*/
48
protected final String baseAlgo;
49
50
/**
51
* The contents of salt are copied to protect against subsequent
52
* modification.
53
*/
54
protected final byte[] salt;
55
56
/**
57
* Password.
58
*/
59
protected final String password;
60
61
/**
62
* PBEWrapper creator.
63
*
64
* @param algo PBE algorithm to test
65
* @param passwd a password phrase
66
* @return PBEWrapper in accordance to requested algo.
67
* @throws GeneralSecurityException all exceptions are thrown.
68
*/
69
public static AbstractPBEWrapper createWrapper(PBEAlgorithm algo, String passwd)
70
throws GeneralSecurityException {
71
switch (algo.type) {
72
case PBKDF2:
73
return new PBKDF2Wrapper(algo, passwd);
74
case AES:
75
return new AESPBEWrapper(algo, passwd);
76
default:
77
return new DefaultPBEWrapper(algo, passwd);
78
}
79
}
80
81
/**
82
* PBEWrapper constructor.
83
*
84
* @param algo algorithm to wrap
85
* @param password password phrase
86
* @param saltSize salt size (defined in subclasses)
87
*/
88
protected AbstractPBEWrapper(PBEAlgorithm algo, String password, int saltSize) {
89
this.transformation = algo.getTransformation();
90
this.baseAlgo = algo.baseAlgo;
91
this.salt = TestUtilities.generateBytes(saltSize);
92
this.password = password;
93
}
94
95
/**
96
* Initialize Cipher object for the operation requested in the mode parameter.
97
*
98
* @param mode encryption or decryption
99
* @return a cipher initialize by mode.
100
* @throws GeneralSecurityException all security exceptions are thrown.
101
*/
102
protected abstract Cipher initCipher(int mode) throws GeneralSecurityException;
103
}
104
105