author | valeriep |
Tue, 08 Jan 2013 11:55:21 -0800 | |
changeset 15010 | ec6b49ce42b1 |
parent 14405 | e7fff80005c1 |
child 16909 | 78a1749a43e2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
15010 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.crypto.provider; |
|
27 |
||
28 |
import java.io.UnsupportedEncodingException; |
|
29 |
import java.math.BigInteger; |
|
30 |
import java.security.*; |
|
31 |
import java.security.spec.*; |
|
32 |
import java.util.Arrays; |
|
33 |
import javax.crypto.*; |
|
34 |
import javax.crypto.spec.*; |
|
35 |
||
36 |
/** |
|
37 |
* This class implements password-base encryption algorithm with |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
38 |
* SHA1 digest and the following Ciphers (in CBC mode, where applicable): |
2 | 39 |
* - DESede cipher and |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
40 |
* - RC2 Cipher with 40-bit or 128-bit effective key length and |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
41 |
* - RC4 Cipher with 40-bit or 128-bit effective key length |
2 | 42 |
* as defined by PKCS #12 version 1.0 standard. |
43 |
* |
|
44 |
* @author Valerie Peng |
|
45 |
* @see javax.crypto.CipherSpi |
|
46 |
*/ |
|
47 |
final class PKCS12PBECipherCore { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
48 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
49 |
// TBD: replace CipherCore with a CipherSpi object to simplify maintenance |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
50 |
|
2 | 51 |
private CipherCore cipher; |
52 |
private int blockSize; |
|
53 |
private int keySize; |
|
54 |
private String algo = null; |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
55 |
private String pbeAlgo = null; |
2 | 56 |
private byte[] salt = null; |
57 |
private int iCount = 0; |
|
58 |
||
59 |
private static final int DEFAULT_SALT_LENGTH = 20; |
|
60 |
private static final int DEFAULT_COUNT = 1024; |
|
61 |
||
62 |
static final int CIPHER_KEY = 1; |
|
63 |
static final int CIPHER_IV = 2; |
|
64 |
static final int MAC_KEY = 3; |
|
65 |
||
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
66 |
// Uses default hash algorithm (SHA-1) |
2 | 67 |
static byte[] derive(char[] chars, byte[] salt, |
68 |
int ic, int n, int type) { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
69 |
return derive(chars, salt, ic, n, type, "SHA-1", 64); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
70 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
71 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
72 |
// Uses supplied hash algorithm |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
73 |
static byte[] derive(char[] chars, byte[] salt, int ic, int n, int type, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
74 |
String hashAlgo, int blockLength) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
75 |
|
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
76 |
// Add in trailing NULL terminator. Special case: |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
77 |
// no terminator if password is "\0". |
2 | 78 |
int length = chars.length*2; |
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
79 |
if (length == 2 && chars[0] == 0) { |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
80 |
chars = new char[0]; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
81 |
length = 0; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
82 |
} else { |
2 | 83 |
length += 2; |
84 |
} |
|
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
85 |
|
2 | 86 |
byte[] passwd = new byte[length]; |
87 |
for (int i = 0, j = 0; i < chars.length; i++, j+=2) { |
|
88 |
passwd[j] = (byte) ((chars[i] >>> 8) & 0xFF); |
|
89 |
passwd[j+1] = (byte) (chars[i] & 0xFF); |
|
90 |
} |
|
91 |
byte[] key = new byte[n]; |
|
92 |
||
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
93 |
try { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
94 |
MessageDigest sha = MessageDigest.getInstance(hashAlgo); |
2 | 95 |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
96 |
int v = blockLength; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
97 |
int u = sha.getDigestLength(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
98 |
int c = roundup(n, u) / u; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
99 |
byte[] D = new byte[v]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
100 |
int s = roundup(salt.length, v); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
101 |
int p = roundup(passwd.length, v); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
102 |
byte[] I = new byte[s + p]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
103 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
104 |
Arrays.fill(D, (byte)type); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
105 |
concat(salt, I, 0, s); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
106 |
concat(passwd, I, s, p); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
107 |
|
2 | 108 |
byte[] Ai; |
109 |
byte[] B = new byte[v]; |
|
110 |
byte[] tmp = new byte[v]; |
|
111 |
||
112 |
int i = 0; |
|
113 |
for (; ; i++, n -= u) { |
|
114 |
sha.update(D); |
|
115 |
sha.update(I); |
|
116 |
Ai = sha.digest(); |
|
117 |
for (int r = 1; r < ic; r++) |
|
118 |
Ai = sha.digest(Ai); |
|
119 |
System.arraycopy(Ai, 0, key, u * i, Math.min(n, u)); |
|
120 |
if (i + 1 == c) |
|
121 |
break; |
|
122 |
concat(Ai, B, 0, B.length); |
|
123 |
BigInteger B1; |
|
124 |
B1 = new BigInteger(1, B).add(BigInteger.ONE); |
|
125 |
||
126 |
for (int j = 0; j < I.length; j += v) { |
|
127 |
BigInteger Ij; |
|
128 |
int trunc; |
|
129 |
||
130 |
if (tmp.length != v) |
|
131 |
tmp = new byte[v]; |
|
132 |
System.arraycopy(I, j, tmp, 0, v); |
|
133 |
Ij = new BigInteger(1, tmp); |
|
134 |
Ij = Ij.add(B1); |
|
135 |
tmp = Ij.toByteArray(); |
|
136 |
trunc = tmp.length - v; |
|
137 |
if (trunc >= 0) { |
|
138 |
System.arraycopy(tmp, trunc, I, j, v); |
|
139 |
} else if (trunc < 0) { |
|
140 |
Arrays.fill(I, j, j + (-trunc), (byte)0); |
|
141 |
System.arraycopy(tmp, 0, I, j + (-trunc), tmp.length); |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
} catch (Exception e) { |
|
146 |
throw new RuntimeException("internal error: " + e); |
|
147 |
} |
|
148 |
return key; |
|
149 |
} |
|
150 |
||
151 |
private static int roundup(int x, int y) { |
|
152 |
return ((x + (y - 1)) / y) * y; |
|
153 |
} |
|
154 |
||
155 |
private static void concat(byte[] src, byte[] dst, int start, int len) { |
|
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
156 |
if (src.length == 0) { |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
157 |
return; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
158 |
} |
2 | 159 |
int loop = len / src.length; |
160 |
int off, i; |
|
161 |
for (i = 0, off = 0; i < loop; i++, off += src.length) |
|
162 |
System.arraycopy(src, 0, dst, off + start, src.length); |
|
163 |
System.arraycopy(src, 0, dst, off + start, len - off); |
|
164 |
} |
|
165 |
||
166 |
PKCS12PBECipherCore(String symmCipherAlg, int defKeySize) |
|
167 |
throws NoSuchAlgorithmException { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
168 |
|
2 | 169 |
algo = symmCipherAlg; |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
170 |
if (algo.equals("RC4")) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
171 |
pbeAlgo = "PBEWithSHA1AndRC4_" + defKeySize * 8; |
2 | 172 |
} else { |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
173 |
SymmetricCipher symmCipher = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
174 |
if (algo.equals("DESede")) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
175 |
symmCipher = new DESedeCrypt(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
176 |
pbeAlgo = "PBEWithSHA1AndDESede"; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
177 |
} else if (algo.equals("RC2")) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
178 |
symmCipher = new RC2Crypt(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
179 |
pbeAlgo = "PBEWithSHA1AndRC2_" + defKeySize * 8; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
180 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
181 |
throw new NoSuchAlgorithmException("No Cipher implementation " + |
2 | 182 |
"for PBEWithSHA1And" + algo); |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
183 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
184 |
blockSize = symmCipher.getBlockSize(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
185 |
cipher = new CipherCore(symmCipher, blockSize); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
186 |
cipher.setMode("CBC"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
187 |
try { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
188 |
cipher.setPadding("PKCS5Padding"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
189 |
} catch (NoSuchPaddingException nspe) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
190 |
// should not happen |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
191 |
} |
2 | 192 |
} |
193 |
keySize = defKeySize; |
|
194 |
} |
|
195 |
||
196 |
void implSetMode(String mode) throws NoSuchAlgorithmException { |
|
197 |
if ((mode != null) && (!mode.equalsIgnoreCase("CBC"))) { |
|
198 |
throw new NoSuchAlgorithmException("Invalid cipher mode: " |
|
199 |
+ mode); |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
void implSetPadding(String padding) throws NoSuchPaddingException { |
|
204 |
if ((padding != null) && |
|
205 |
(!padding.equalsIgnoreCase("PKCS5Padding"))) { |
|
206 |
throw new NoSuchPaddingException("Invalid padding scheme: " + |
|
207 |
padding); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
int implGetBlockSize() { |
|
212 |
return blockSize; |
|
213 |
} |
|
214 |
||
215 |
int implGetOutputSize(int inLen) { |
|
216 |
return cipher.getOutputSize(inLen); |
|
217 |
} |
|
218 |
||
219 |
byte[] implGetIV() { |
|
220 |
return cipher.getIV(); |
|
221 |
} |
|
222 |
||
223 |
AlgorithmParameters implGetParameters() { |
|
224 |
AlgorithmParameters params = null; |
|
225 |
if (salt == null) { |
|
226 |
// Cipher is not initialized with parameters; |
|
227 |
// follow the recommendation in PKCS12 v1.0 |
|
228 |
// section B.4 to generate salt and iCount. |
|
229 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
|
15010 | 230 |
SunJCE.getRandom().nextBytes(salt); |
2 | 231 |
iCount = DEFAULT_COUNT; |
232 |
} |
|
233 |
PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iCount); |
|
234 |
try { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
235 |
params = AlgorithmParameters.getInstance(pbeAlgo, "SunJCE"); |
2 | 236 |
} catch (GeneralSecurityException gse) { |
237 |
// should never happen |
|
7043 | 238 |
throw new RuntimeException( |
239 |
"SunJCE provider is not configured properly"); |
|
2 | 240 |
} |
241 |
try { |
|
242 |
params.init(pbeSpec); |
|
243 |
} catch (InvalidParameterSpecException ipse) { |
|
244 |
// should never happen |
|
245 |
throw new RuntimeException("PBEParameterSpec not supported"); |
|
246 |
} |
|
247 |
return params; |
|
248 |
} |
|
249 |
||
250 |
void implInit(int opmode, Key key, AlgorithmParameterSpec params, |
|
251 |
SecureRandom random) throws InvalidKeyException, |
|
252 |
InvalidAlgorithmParameterException { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
253 |
implInit(opmode, key, params, random, null); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
254 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
255 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
256 |
void implInit(int opmode, Key key, AlgorithmParameterSpec params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
257 |
SecureRandom random, CipherSpi cipherImpl) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
258 |
throws InvalidKeyException, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
259 |
InvalidAlgorithmParameterException { |
2 | 260 |
char[] passwdChars = null; |
261 |
salt = null; |
|
262 |
iCount = 0; |
|
263 |
if (key instanceof javax.crypto.interfaces.PBEKey) { |
|
264 |
javax.crypto.interfaces.PBEKey pbeKey = |
|
265 |
(javax.crypto.interfaces.PBEKey) key; |
|
266 |
passwdChars = pbeKey.getPassword(); |
|
267 |
salt = pbeKey.getSalt(); // maybe null if unspecified |
|
268 |
iCount = pbeKey.getIterationCount(); // maybe 0 if unspecified |
|
269 |
} else if (key instanceof SecretKey) { |
|
270 |
byte[] passwdBytes = key.getEncoded(); |
|
271 |
if ((passwdBytes == null) || |
|
272 |
!(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) { |
|
273 |
throw new InvalidKeyException("Missing password"); |
|
274 |
} |
|
275 |
passwdChars = new char[passwdBytes.length]; |
|
276 |
for (int i=0; i<passwdChars.length; i++) { |
|
277 |
passwdChars[i] = (char) (passwdBytes[i] & 0x7f); |
|
278 |
} |
|
279 |
} else { |
|
280 |
throw new InvalidKeyException("SecretKey of PBE type required"); |
|
281 |
} |
|
282 |
||
283 |
if (((opmode == Cipher.DECRYPT_MODE) || |
|
284 |
(opmode == Cipher.UNWRAP_MODE)) && |
|
285 |
((params == null) && ((salt == null) || (iCount == 0)))) { |
|
286 |
throw new InvalidAlgorithmParameterException |
|
287 |
("Parameters missing"); |
|
288 |
} |
|
289 |
||
290 |
if (params == null) { |
|
291 |
// generate default for salt and iteration count if necessary |
|
292 |
if (salt == null) { |
|
293 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
|
294 |
if (random != null) { |
|
295 |
random.nextBytes(salt); |
|
296 |
} else { |
|
15010 | 297 |
SunJCE.getRandom().nextBytes(salt); |
2 | 298 |
} |
299 |
} |
|
300 |
if (iCount == 0) iCount = DEFAULT_COUNT; |
|
301 |
} else if (!(params instanceof PBEParameterSpec)) { |
|
302 |
throw new InvalidAlgorithmParameterException |
|
303 |
("PBEParameterSpec type required"); |
|
304 |
} else { |
|
305 |
PBEParameterSpec pbeParams = (PBEParameterSpec) params; |
|
306 |
// make sure the parameter values are consistent |
|
307 |
if (salt != null) { |
|
308 |
if (!Arrays.equals(salt, pbeParams.getSalt())) { |
|
309 |
throw new InvalidAlgorithmParameterException |
|
310 |
("Inconsistent value of salt between key and params"); |
|
311 |
} |
|
312 |
} else { |
|
313 |
salt = pbeParams.getSalt(); |
|
314 |
} |
|
315 |
if (iCount != 0) { |
|
316 |
if (iCount != pbeParams.getIterationCount()) { |
|
317 |
throw new InvalidAlgorithmParameterException |
|
318 |
("Different iteration count between key and params"); |
|
319 |
} |
|
320 |
} else { |
|
321 |
iCount = pbeParams.getIterationCount(); |
|
322 |
} |
|
323 |
} |
|
324 |
// salt is recommended to be ideally as long as the output |
|
325 |
// of the hash function. However, it may be too strict to |
|
326 |
// force this; so instead, we'll just require the minimum |
|
327 |
// salt length to be 8-byte which is what PKCS#5 recommends |
|
328 |
// and openssl does. |
|
329 |
if (salt.length < 8) { |
|
330 |
throw new InvalidAlgorithmParameterException |
|
331 |
("Salt must be at least 8 bytes long"); |
|
332 |
} |
|
333 |
if (iCount <= 0) { |
|
334 |
throw new InvalidAlgorithmParameterException |
|
335 |
("IterationCount must be a positive number"); |
|
336 |
} |
|
337 |
byte[] derivedKey = derive(passwdChars, salt, iCount, |
|
338 |
keySize, CIPHER_KEY); |
|
339 |
SecretKey cipherKey = new SecretKeySpec(derivedKey, algo); |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
340 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
341 |
if (cipherImpl != null && cipherImpl instanceof ARCFOURCipher) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
342 |
((ARCFOURCipher)cipherImpl).engineInit(opmode, cipherKey, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
343 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
344 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
345 |
byte[] derivedIv = derive(passwdChars, salt, iCount, 8, |
2 | 346 |
CIPHER_IV); |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
347 |
IvParameterSpec ivSpec = new IvParameterSpec(derivedIv, 0, 8); |
2 | 348 |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
349 |
// initialize the underlying cipher |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
350 |
cipher.init(opmode, cipherKey, ivSpec, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
351 |
} |
2 | 352 |
} |
353 |
||
354 |
void implInit(int opmode, Key key, AlgorithmParameters params, |
|
355 |
SecureRandom random) |
|
356 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
357 |
implInit(opmode, key, params, random, null); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
358 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
359 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
360 |
void implInit(int opmode, Key key, AlgorithmParameters params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
361 |
SecureRandom random, CipherSpi cipherImpl) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
362 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
2 | 363 |
AlgorithmParameterSpec paramSpec = null; |
364 |
if (params != null) { |
|
365 |
try { |
|
366 |
paramSpec = params.getParameterSpec(PBEParameterSpec.class); |
|
367 |
} catch (InvalidParameterSpecException ipse) { |
|
7043 | 368 |
throw new InvalidAlgorithmParameterException( |
369 |
"requires PBE parameters"); |
|
2 | 370 |
} |
371 |
} |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
372 |
implInit(opmode, key, paramSpec, random, cipherImpl); |
2 | 373 |
} |
374 |
||
375 |
void implInit(int opmode, Key key, SecureRandom random) |
|
376 |
throws InvalidKeyException { |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
377 |
implInit(opmode, key, random, null); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
378 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
379 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
380 |
void implInit(int opmode, Key key, SecureRandom random, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
381 |
CipherSpi cipherImpl) throws InvalidKeyException { |
2 | 382 |
try { |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
383 |
implInit(opmode, key, (AlgorithmParameterSpec) null, random, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
384 |
cipherImpl); |
2 | 385 |
} catch (InvalidAlgorithmParameterException iape) { |
386 |
throw new InvalidKeyException("requires PBE parameters"); |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
byte[] implUpdate(byte[] in, int inOff, int inLen) { |
|
391 |
return cipher.update(in, inOff, inLen); |
|
392 |
} |
|
393 |
||
394 |
int implUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff) |
|
395 |
throws ShortBufferException { |
|
396 |
return cipher.update(in, inOff, inLen, out, outOff); |
|
397 |
} |
|
398 |
||
399 |
byte[] implDoFinal(byte[] in, int inOff, int inLen) |
|
400 |
throws IllegalBlockSizeException, BadPaddingException { |
|
401 |
return cipher.doFinal(in, inOff, inLen); |
|
402 |
} |
|
403 |
||
404 |
int implDoFinal(byte[] in, int inOff, int inLen, byte[] out, int outOff) |
|
405 |
throws ShortBufferException, IllegalBlockSizeException, |
|
406 |
BadPaddingException { |
|
407 |
return cipher.doFinal(in, inOff, inLen, out, outOff); |
|
408 |
} |
|
409 |
||
410 |
int implGetKeySize(Key key) throws InvalidKeyException { |
|
411 |
return keySize; |
|
412 |
} |
|
413 |
||
414 |
byte[] implWrap(Key key) throws IllegalBlockSizeException, |
|
415 |
InvalidKeyException { |
|
416 |
return cipher.wrap(key); |
|
417 |
} |
|
418 |
||
419 |
Key implUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, |
|
420 |
int wrappedKeyType) |
|
421 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
422 |
return cipher.unwrap(wrappedKey, wrappedKeyAlgorithm, |
|
423 |
wrappedKeyType); |
|
424 |
} |
|
425 |
||
426 |
public static final class PBEWithSHA1AndDESede extends CipherSpi { |
|
427 |
private final PKCS12PBECipherCore core; |
|
428 |
public PBEWithSHA1AndDESede() throws NoSuchAlgorithmException { |
|
429 |
core = new PKCS12PBECipherCore("DESede", 24); |
|
430 |
} |
|
431 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
|
432 |
throws IllegalBlockSizeException, BadPaddingException { |
|
433 |
return core.implDoFinal(in, inOff, inLen); |
|
434 |
} |
|
435 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
|
436 |
byte[] out, int outOff) |
|
437 |
throws ShortBufferException, IllegalBlockSizeException, |
|
438 |
BadPaddingException { |
|
439 |
return core.implDoFinal(in, inOff, inLen, out, outOff); |
|
440 |
} |
|
441 |
protected int engineGetBlockSize() { |
|
442 |
return core.implGetBlockSize(); |
|
443 |
} |
|
444 |
protected byte[] engineGetIV() { |
|
445 |
return core.implGetIV(); |
|
446 |
} |
|
447 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
|
448 |
return core.implGetKeySize(key); |
|
449 |
} |
|
450 |
protected int engineGetOutputSize(int inLen) { |
|
451 |
return core.implGetOutputSize(inLen); |
|
452 |
} |
|
453 |
protected AlgorithmParameters engineGetParameters() { |
|
454 |
return core.implGetParameters(); |
|
455 |
} |
|
456 |
protected void engineInit(int opmode, Key key, |
|
457 |
AlgorithmParameterSpec params, |
|
458 |
SecureRandom random) |
|
459 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
460 |
core.implInit(opmode, key, params, random); |
|
461 |
} |
|
462 |
protected void engineInit(int opmode, Key key, |
|
463 |
AlgorithmParameters params, |
|
464 |
SecureRandom random) |
|
465 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
466 |
core.implInit(opmode, key, params, random); |
|
467 |
} |
|
468 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
|
469 |
throws InvalidKeyException { |
|
470 |
core.implInit(opmode, key, random); |
|
471 |
} |
|
472 |
protected void engineSetMode(String mode) |
|
473 |
throws NoSuchAlgorithmException { |
|
474 |
core.implSetMode(mode); |
|
475 |
} |
|
476 |
protected void engineSetPadding(String paddingScheme) |
|
477 |
throws NoSuchPaddingException { |
|
478 |
core.implSetPadding(paddingScheme); |
|
479 |
} |
|
480 |
protected Key engineUnwrap(byte[] wrappedKey, |
|
481 |
String wrappedKeyAlgorithm, |
|
482 |
int wrappedKeyType) |
|
483 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
484 |
return core.implUnwrap(wrappedKey, wrappedKeyAlgorithm, |
|
485 |
wrappedKeyType); |
|
486 |
} |
|
487 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
|
488 |
return core.implUpdate(in, inOff, inLen); |
|
489 |
} |
|
490 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
|
491 |
byte[] out, int outOff) |
|
492 |
throws ShortBufferException { |
|
493 |
return core.implUpdate(in, inOff, inLen, out, outOff); |
|
494 |
} |
|
495 |
protected byte[] engineWrap(Key key) |
|
496 |
throws IllegalBlockSizeException, InvalidKeyException { |
|
497 |
return core.implWrap(key); |
|
498 |
} |
|
499 |
} |
|
500 |
||
501 |
public static final class PBEWithSHA1AndRC2_40 extends CipherSpi { |
|
502 |
private final PKCS12PBECipherCore core; |
|
503 |
public PBEWithSHA1AndRC2_40() throws NoSuchAlgorithmException { |
|
504 |
core = new PKCS12PBECipherCore("RC2", 5); |
|
505 |
} |
|
506 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
|
507 |
throws IllegalBlockSizeException, BadPaddingException { |
|
508 |
return core.implDoFinal(in, inOff, inLen); |
|
509 |
} |
|
510 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
|
511 |
byte[] out, int outOff) |
|
512 |
throws ShortBufferException, IllegalBlockSizeException, |
|
513 |
BadPaddingException { |
|
514 |
return core.implDoFinal(in, inOff, inLen, out, outOff); |
|
515 |
} |
|
516 |
protected int engineGetBlockSize() { |
|
517 |
return core.implGetBlockSize(); |
|
518 |
} |
|
519 |
protected byte[] engineGetIV() { |
|
520 |
return core.implGetIV(); |
|
521 |
} |
|
522 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
|
523 |
return core.implGetKeySize(key); |
|
524 |
} |
|
525 |
protected int engineGetOutputSize(int inLen) { |
|
526 |
return core.implGetOutputSize(inLen); |
|
527 |
} |
|
528 |
protected AlgorithmParameters engineGetParameters() { |
|
529 |
return core.implGetParameters(); |
|
530 |
} |
|
531 |
protected void engineInit(int opmode, Key key, |
|
532 |
AlgorithmParameterSpec params, |
|
533 |
SecureRandom random) |
|
534 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
535 |
core.implInit(opmode, key, params, random); |
|
536 |
} |
|
537 |
protected void engineInit(int opmode, Key key, |
|
538 |
AlgorithmParameters params, |
|
539 |
SecureRandom random) |
|
540 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
541 |
core.implInit(opmode, key, params, random); |
|
542 |
} |
|
543 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
|
544 |
throws InvalidKeyException { |
|
545 |
core.implInit(opmode, key, random); |
|
546 |
} |
|
547 |
protected void engineSetMode(String mode) |
|
548 |
throws NoSuchAlgorithmException { |
|
549 |
core.implSetMode(mode); |
|
550 |
} |
|
551 |
protected void engineSetPadding(String paddingScheme) |
|
552 |
throws NoSuchPaddingException { |
|
553 |
core.implSetPadding(paddingScheme); |
|
554 |
} |
|
555 |
protected Key engineUnwrap(byte[] wrappedKey, |
|
556 |
String wrappedKeyAlgorithm, |
|
557 |
int wrappedKeyType) |
|
558 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
559 |
return core.implUnwrap(wrappedKey, wrappedKeyAlgorithm, |
|
560 |
wrappedKeyType); |
|
561 |
} |
|
562 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
|
563 |
return core.implUpdate(in, inOff, inLen); |
|
564 |
} |
|
565 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
|
566 |
byte[] out, int outOff) |
|
567 |
throws ShortBufferException { |
|
568 |
return core.implUpdate(in, inOff, inLen, out, outOff); |
|
569 |
} |
|
570 |
protected byte[] engineWrap(Key key) |
|
571 |
throws IllegalBlockSizeException, InvalidKeyException { |
|
572 |
return core.implWrap(key); |
|
573 |
} |
|
574 |
} |
|
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
575 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
576 |
public static final class PBEWithSHA1AndRC2_128 extends CipherSpi { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
577 |
private final PKCS12PBECipherCore core; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
578 |
public PBEWithSHA1AndRC2_128() throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
579 |
core = new PKCS12PBECipherCore("RC2", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
580 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
581 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
582 |
throws IllegalBlockSizeException, BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
583 |
return core.implDoFinal(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
584 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
585 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
586 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
587 |
throws ShortBufferException, IllegalBlockSizeException, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
588 |
BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
589 |
return core.implDoFinal(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
590 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
591 |
protected int engineGetBlockSize() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
592 |
return core.implGetBlockSize(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
593 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
594 |
protected byte[] engineGetIV() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
595 |
return core.implGetIV(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
596 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
597 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
598 |
return core.implGetKeySize(key); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
599 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
600 |
protected int engineGetOutputSize(int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
601 |
return core.implGetOutputSize(inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
602 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
603 |
protected AlgorithmParameters engineGetParameters() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
604 |
return core.implGetParameters(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
605 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
606 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
607 |
AlgorithmParameterSpec params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
608 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
609 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
610 |
core.implInit(opmode, key, params, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
611 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
612 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
613 |
AlgorithmParameters params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
614 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
615 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
616 |
core.implInit(opmode, key, params, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
617 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
618 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
619 |
throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
620 |
core.implInit(opmode, key, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
621 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
622 |
protected void engineSetMode(String mode) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
623 |
throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
624 |
core.implSetMode(mode); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
625 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
626 |
protected void engineSetPadding(String paddingScheme) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
627 |
throws NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
628 |
core.implSetPadding(paddingScheme); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
629 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
630 |
protected Key engineUnwrap(byte[] wrappedKey, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
631 |
String wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
632 |
int wrappedKeyType) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
633 |
throws InvalidKeyException, NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
634 |
return core.implUnwrap(wrappedKey, wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
635 |
wrappedKeyType); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
636 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
637 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
638 |
return core.implUpdate(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
639 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
640 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
641 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
642 |
throws ShortBufferException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
643 |
return core.implUpdate(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
644 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
645 |
protected byte[] engineWrap(Key key) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
646 |
throws IllegalBlockSizeException, InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
647 |
return core.implWrap(key); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
648 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
649 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
650 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
651 |
public static final class PBEWithSHA1AndRC4_40 extends CipherSpi { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
652 |
private static final int RC4_KEYSIZE = 5; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
653 |
private final PKCS12PBECipherCore core; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
654 |
private final ARCFOURCipher cipher; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
655 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
656 |
public PBEWithSHA1AndRC4_40() throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
657 |
core = new PKCS12PBECipherCore("RC4", RC4_KEYSIZE); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
658 |
cipher = new ARCFOURCipher(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
659 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
660 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
661 |
throws IllegalBlockSizeException, BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
662 |
return cipher.engineDoFinal(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
663 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
664 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
665 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
666 |
throws ShortBufferException, IllegalBlockSizeException, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
667 |
BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
668 |
return cipher.engineDoFinal(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
669 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
670 |
protected int engineGetBlockSize() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
671 |
return cipher.engineGetBlockSize(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
672 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
673 |
protected byte[] engineGetIV() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
674 |
return cipher.engineGetIV(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
675 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
676 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
677 |
return RC4_KEYSIZE; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
678 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
679 |
protected int engineGetOutputSize(int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
680 |
return cipher.engineGetOutputSize(inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
681 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
682 |
protected AlgorithmParameters engineGetParameters() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
683 |
return core.implGetParameters(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
684 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
685 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
686 |
AlgorithmParameterSpec params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
687 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
688 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
689 |
core.implInit(opmode, key, params, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
690 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
691 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
692 |
AlgorithmParameters params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
693 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
694 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
695 |
core.implInit(opmode, key, params, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
696 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
697 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
698 |
throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
699 |
core.implInit(opmode, key, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
700 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
701 |
protected void engineSetMode(String mode) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
702 |
throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
703 |
if (mode.equalsIgnoreCase("ECB") == false) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
704 |
throw new NoSuchAlgorithmException("Unsupported mode " + mode); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
705 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
706 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
707 |
protected void engineSetPadding(String paddingScheme) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
708 |
throws NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
709 |
if (paddingScheme.equalsIgnoreCase("NoPadding") == false) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
710 |
throw new NoSuchPaddingException("Padding must be NoPadding"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
711 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
712 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
713 |
protected Key engineUnwrap(byte[] wrappedKey, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
714 |
String wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
715 |
int wrappedKeyType) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
716 |
throws InvalidKeyException, NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
717 |
return cipher.engineUnwrap(wrappedKey, wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
718 |
wrappedKeyType); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
719 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
720 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
721 |
return cipher.engineUpdate(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
722 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
723 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
724 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
725 |
throws ShortBufferException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
726 |
return cipher.engineUpdate(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
727 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
728 |
protected byte[] engineWrap(Key key) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
729 |
throws IllegalBlockSizeException, InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
730 |
return cipher.engineWrap(key); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
731 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
732 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
733 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
734 |
public static final class PBEWithSHA1AndRC4_128 extends CipherSpi { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
735 |
private static final int RC4_KEYSIZE = 16; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
736 |
private final PKCS12PBECipherCore core; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
737 |
private final ARCFOURCipher cipher; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
738 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
739 |
public PBEWithSHA1AndRC4_128() throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
740 |
core = new PKCS12PBECipherCore("RC4", RC4_KEYSIZE); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
741 |
cipher = new ARCFOURCipher(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
742 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
743 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
744 |
throws IllegalBlockSizeException, BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
745 |
return cipher.engineDoFinal(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
746 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
747 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
748 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
749 |
throws ShortBufferException, IllegalBlockSizeException, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
750 |
BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
751 |
return cipher.engineDoFinal(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
752 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
753 |
protected int engineGetBlockSize() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
754 |
return cipher.engineGetBlockSize(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
755 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
756 |
protected byte[] engineGetIV() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
757 |
return cipher.engineGetIV(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
758 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
759 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
760 |
return RC4_KEYSIZE; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
761 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
762 |
protected int engineGetOutputSize(int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
763 |
return cipher.engineGetOutputSize(inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
764 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
765 |
protected AlgorithmParameters engineGetParameters() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
766 |
return core.implGetParameters(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
767 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
768 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
769 |
AlgorithmParameterSpec params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
770 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
771 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
772 |
core.implInit(opmode, key, params, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
773 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
774 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
775 |
AlgorithmParameters params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
776 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
777 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
778 |
core.implInit(opmode, key, params, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
779 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
780 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
781 |
throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
782 |
core.implInit(opmode, key, random, cipher); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
783 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
784 |
protected void engineSetMode(String mode) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
785 |
throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
786 |
if (mode.equalsIgnoreCase("ECB") == false) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
787 |
throw new NoSuchAlgorithmException("Unsupported mode " + mode); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
788 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
789 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
790 |
protected void engineSetPadding(String paddingScheme) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
791 |
throws NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
792 |
if (paddingScheme.equalsIgnoreCase("NoPadding") == false) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
793 |
throw new NoSuchPaddingException("Padding must be NoPadding"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
794 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
795 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
796 |
protected Key engineUnwrap(byte[] wrappedKey, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
797 |
String wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
798 |
int wrappedKeyType) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
799 |
throws InvalidKeyException, NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
800 |
return cipher.engineUnwrap(wrappedKey, wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
801 |
wrappedKeyType); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
802 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
803 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
804 |
return cipher.engineUpdate(in, inOff, inLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
805 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
806 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
807 |
byte[] out, int outOff) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
808 |
throws ShortBufferException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
809 |
return cipher.engineUpdate(in, inOff, inLen, out, outOff); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
810 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
811 |
protected byte[] engineWrap(Key key) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
812 |
throws IllegalBlockSizeException, InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
813 |
return cipher.engineWrap(key); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
814 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
14342
diff
changeset
|
815 |
} |
2 | 816 |
} |