author | valeriep |
Tue, 08 May 2012 17:57:48 -0700 | |
changeset 12685 | 8a448b5b9006 |
parent 11835 | c9e7cfc908b3 |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7043 | 2 |
* Copyright (c) 2003, 2010, 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 |
|
38 |
* SHA1 digest and the following Ciphers in CBC mode |
|
39 |
* - DESede cipher and |
|
40 |
* - RC2 Cipher with 40-bit effective key length |
|
41 |
* as defined by PKCS #12 version 1.0 standard. |
|
42 |
* |
|
43 |
* @author Valerie Peng |
|
44 |
* @see javax.crypto.CipherSpi |
|
45 |
*/ |
|
46 |
final class PKCS12PBECipherCore { |
|
47 |
private CipherCore cipher; |
|
48 |
private int blockSize; |
|
49 |
private int keySize; |
|
50 |
private String algo = null; |
|
51 |
private byte[] salt = null; |
|
52 |
private int iCount = 0; |
|
53 |
||
54 |
private static final int DEFAULT_SALT_LENGTH = 20; |
|
55 |
private static final int DEFAULT_COUNT = 1024; |
|
56 |
||
57 |
static final int CIPHER_KEY = 1; |
|
58 |
static final int CIPHER_IV = 2; |
|
59 |
static final int MAC_KEY = 3; |
|
60 |
||
61 |
static byte[] derive(char[] chars, byte[] salt, |
|
62 |
int ic, int n, int type) { |
|
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
63 |
// Add in trailing NULL terminator. Special case: |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
64 |
// no terminator if password is "\0". |
2 | 65 |
int length = chars.length*2; |
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
66 |
if (length == 2 && chars[0] == 0) { |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
67 |
chars = new char[0]; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
68 |
length = 0; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
69 |
} else { |
2 | 70 |
length += 2; |
71 |
} |
|
11835
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
72 |
|
2 | 73 |
byte[] passwd = new byte[length]; |
74 |
for (int i = 0, j = 0; i < chars.length; i++, j+=2) { |
|
75 |
passwd[j] = (byte) ((chars[i] >>> 8) & 0xFF); |
|
76 |
passwd[j+1] = (byte) (chars[i] & 0xFF); |
|
77 |
} |
|
78 |
int v = 512 / 8; |
|
79 |
int u = 160 / 8; |
|
80 |
int c = roundup(n, u) / u; |
|
81 |
byte[] D = new byte[v]; |
|
82 |
int s = roundup(salt.length, v); |
|
83 |
int p = roundup(passwd.length, v); |
|
84 |
byte[] I = new byte[s + p]; |
|
85 |
byte[] key = new byte[n]; |
|
86 |
||
87 |
Arrays.fill(D, (byte)type); |
|
88 |
concat(salt, I, 0, s); |
|
89 |
concat(passwd, I, s, p); |
|
90 |
||
91 |
try { |
|
92 |
MessageDigest sha = MessageDigest.getInstance("SHA1"); |
|
93 |
byte[] Ai; |
|
94 |
byte[] B = new byte[v]; |
|
95 |
byte[] tmp = new byte[v]; |
|
96 |
||
97 |
int i = 0; |
|
98 |
for (; ; i++, n -= u) { |
|
99 |
sha.update(D); |
|
100 |
sha.update(I); |
|
101 |
Ai = sha.digest(); |
|
102 |
for (int r = 1; r < ic; r++) |
|
103 |
Ai = sha.digest(Ai); |
|
104 |
System.arraycopy(Ai, 0, key, u * i, Math.min(n, u)); |
|
105 |
if (i + 1 == c) |
|
106 |
break; |
|
107 |
concat(Ai, B, 0, B.length); |
|
108 |
BigInteger B1; |
|
109 |
B1 = new BigInteger(1, B).add(BigInteger.ONE); |
|
110 |
||
111 |
for (int j = 0; j < I.length; j += v) { |
|
112 |
BigInteger Ij; |
|
113 |
int trunc; |
|
114 |
||
115 |
if (tmp.length != v) |
|
116 |
tmp = new byte[v]; |
|
117 |
System.arraycopy(I, j, tmp, 0, v); |
|
118 |
Ij = new BigInteger(1, tmp); |
|
119 |
Ij = Ij.add(B1); |
|
120 |
tmp = Ij.toByteArray(); |
|
121 |
trunc = tmp.length - v; |
|
122 |
if (trunc >= 0) { |
|
123 |
System.arraycopy(tmp, trunc, I, j, v); |
|
124 |
} else if (trunc < 0) { |
|
125 |
Arrays.fill(I, j, j + (-trunc), (byte)0); |
|
126 |
System.arraycopy(tmp, 0, I, j + (-trunc), tmp.length); |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
} catch (Exception e) { |
|
131 |
throw new RuntimeException("internal error: " + e); |
|
132 |
} |
|
133 |
return key; |
|
134 |
} |
|
135 |
||
136 |
private static int roundup(int x, int y) { |
|
137 |
return ((x + (y - 1)) / y) * y; |
|
138 |
} |
|
139 |
||
140 |
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
|
141 |
if (src.length == 0) { |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
142 |
return; |
c9e7cfc908b3
6879539: enable empty password support for pkcs12 keystore
weijun
parents:
7043
diff
changeset
|
143 |
} |
2 | 144 |
int loop = len / src.length; |
145 |
int off, i; |
|
146 |
for (i = 0, off = 0; i < loop; i++, off += src.length) |
|
147 |
System.arraycopy(src, 0, dst, off + start, src.length); |
|
148 |
System.arraycopy(src, 0, dst, off + start, len - off); |
|
149 |
} |
|
150 |
||
151 |
PKCS12PBECipherCore(String symmCipherAlg, int defKeySize) |
|
152 |
throws NoSuchAlgorithmException { |
|
153 |
algo = symmCipherAlg; |
|
154 |
SymmetricCipher symmCipher = null; |
|
155 |
if (algo.equals("DESede")) { |
|
156 |
symmCipher = new DESedeCrypt(); |
|
157 |
} else if (algo.equals("RC2")) { |
|
158 |
symmCipher = new RC2Crypt(); |
|
159 |
} else { |
|
160 |
throw new NoSuchAlgorithmException("No Cipher implementation " + |
|
161 |
"for PBEWithSHA1And" + algo); |
|
162 |
} |
|
163 |
blockSize = symmCipher.getBlockSize(); |
|
164 |
cipher = new CipherCore(symmCipher, blockSize); |
|
165 |
cipher.setMode("CBC"); |
|
166 |
try { |
|
167 |
cipher.setPadding("PKCS5Padding"); |
|
168 |
} catch (NoSuchPaddingException nspe) { |
|
169 |
// should not happen |
|
170 |
} |
|
171 |
keySize = defKeySize; |
|
172 |
} |
|
173 |
||
174 |
void implSetMode(String mode) throws NoSuchAlgorithmException { |
|
175 |
if ((mode != null) && (!mode.equalsIgnoreCase("CBC"))) { |
|
176 |
throw new NoSuchAlgorithmException("Invalid cipher mode: " |
|
177 |
+ mode); |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
void implSetPadding(String padding) throws NoSuchPaddingException { |
|
182 |
if ((padding != null) && |
|
183 |
(!padding.equalsIgnoreCase("PKCS5Padding"))) { |
|
184 |
throw new NoSuchPaddingException("Invalid padding scheme: " + |
|
185 |
padding); |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
int implGetBlockSize() { |
|
190 |
return blockSize; |
|
191 |
} |
|
192 |
||
193 |
int implGetOutputSize(int inLen) { |
|
194 |
return cipher.getOutputSize(inLen); |
|
195 |
} |
|
196 |
||
197 |
byte[] implGetIV() { |
|
198 |
return cipher.getIV(); |
|
199 |
} |
|
200 |
||
201 |
AlgorithmParameters implGetParameters() { |
|
202 |
AlgorithmParameters params = null; |
|
203 |
if (salt == null) { |
|
204 |
// Cipher is not initialized with parameters; |
|
205 |
// follow the recommendation in PKCS12 v1.0 |
|
206 |
// section B.4 to generate salt and iCount. |
|
207 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
|
208 |
SunJCE.RANDOM.nextBytes(salt); |
|
209 |
iCount = DEFAULT_COUNT; |
|
210 |
} |
|
211 |
PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iCount); |
|
212 |
try { |
|
213 |
params = AlgorithmParameters.getInstance("PBEWithSHA1And" + |
|
214 |
(algo.equalsIgnoreCase("RC2")?"RC2_40":algo), "SunJCE"); |
|
215 |
} catch (GeneralSecurityException gse) { |
|
216 |
// should never happen |
|
7043 | 217 |
throw new RuntimeException( |
218 |
"SunJCE provider is not configured properly"); |
|
2 | 219 |
} |
220 |
try { |
|
221 |
params.init(pbeSpec); |
|
222 |
} catch (InvalidParameterSpecException ipse) { |
|
223 |
// should never happen |
|
224 |
throw new RuntimeException("PBEParameterSpec not supported"); |
|
225 |
} |
|
226 |
return params; |
|
227 |
} |
|
228 |
||
229 |
void implInit(int opmode, Key key, AlgorithmParameterSpec params, |
|
230 |
SecureRandom random) throws InvalidKeyException, |
|
231 |
InvalidAlgorithmParameterException { |
|
232 |
char[] passwdChars = null; |
|
233 |
salt = null; |
|
234 |
iCount = 0; |
|
235 |
if (key instanceof javax.crypto.interfaces.PBEKey) { |
|
236 |
javax.crypto.interfaces.PBEKey pbeKey = |
|
237 |
(javax.crypto.interfaces.PBEKey) key; |
|
238 |
passwdChars = pbeKey.getPassword(); |
|
239 |
salt = pbeKey.getSalt(); // maybe null if unspecified |
|
240 |
iCount = pbeKey.getIterationCount(); // maybe 0 if unspecified |
|
241 |
} else if (key instanceof SecretKey) { |
|
242 |
byte[] passwdBytes = key.getEncoded(); |
|
243 |
if ((passwdBytes == null) || |
|
244 |
!(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) { |
|
245 |
throw new InvalidKeyException("Missing password"); |
|
246 |
} |
|
247 |
passwdChars = new char[passwdBytes.length]; |
|
248 |
for (int i=0; i<passwdChars.length; i++) { |
|
249 |
passwdChars[i] = (char) (passwdBytes[i] & 0x7f); |
|
250 |
} |
|
251 |
} else { |
|
252 |
throw new InvalidKeyException("SecretKey of PBE type required"); |
|
253 |
} |
|
254 |
||
255 |
if (((opmode == Cipher.DECRYPT_MODE) || |
|
256 |
(opmode == Cipher.UNWRAP_MODE)) && |
|
257 |
((params == null) && ((salt == null) || (iCount == 0)))) { |
|
258 |
throw new InvalidAlgorithmParameterException |
|
259 |
("Parameters missing"); |
|
260 |
} |
|
261 |
||
262 |
if (params == null) { |
|
263 |
// generate default for salt and iteration count if necessary |
|
264 |
if (salt == null) { |
|
265 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
|
266 |
if (random != null) { |
|
267 |
random.nextBytes(salt); |
|
268 |
} else { |
|
269 |
SunJCE.RANDOM.nextBytes(salt); |
|
270 |
} |
|
271 |
} |
|
272 |
if (iCount == 0) iCount = DEFAULT_COUNT; |
|
273 |
} else if (!(params instanceof PBEParameterSpec)) { |
|
274 |
throw new InvalidAlgorithmParameterException |
|
275 |
("PBEParameterSpec type required"); |
|
276 |
} else { |
|
277 |
PBEParameterSpec pbeParams = (PBEParameterSpec) params; |
|
278 |
// make sure the parameter values are consistent |
|
279 |
if (salt != null) { |
|
280 |
if (!Arrays.equals(salt, pbeParams.getSalt())) { |
|
281 |
throw new InvalidAlgorithmParameterException |
|
282 |
("Inconsistent value of salt between key and params"); |
|
283 |
} |
|
284 |
} else { |
|
285 |
salt = pbeParams.getSalt(); |
|
286 |
} |
|
287 |
if (iCount != 0) { |
|
288 |
if (iCount != pbeParams.getIterationCount()) { |
|
289 |
throw new InvalidAlgorithmParameterException |
|
290 |
("Different iteration count between key and params"); |
|
291 |
} |
|
292 |
} else { |
|
293 |
iCount = pbeParams.getIterationCount(); |
|
294 |
} |
|
295 |
} |
|
296 |
// salt is recommended to be ideally as long as the output |
|
297 |
// of the hash function. However, it may be too strict to |
|
298 |
// force this; so instead, we'll just require the minimum |
|
299 |
// salt length to be 8-byte which is what PKCS#5 recommends |
|
300 |
// and openssl does. |
|
301 |
if (salt.length < 8) { |
|
302 |
throw new InvalidAlgorithmParameterException |
|
303 |
("Salt must be at least 8 bytes long"); |
|
304 |
} |
|
305 |
if (iCount <= 0) { |
|
306 |
throw new InvalidAlgorithmParameterException |
|
307 |
("IterationCount must be a positive number"); |
|
308 |
} |
|
309 |
byte[] derivedKey = derive(passwdChars, salt, iCount, |
|
310 |
keySize, CIPHER_KEY); |
|
311 |
SecretKey cipherKey = new SecretKeySpec(derivedKey, algo); |
|
312 |
byte[] derivedIv = derive(passwdChars, salt, iCount, 8, |
|
313 |
CIPHER_IV); |
|
314 |
IvParameterSpec ivSpec = new IvParameterSpec(derivedIv, 0, 8); |
|
315 |
||
316 |
// initialize the underlying cipher |
|
317 |
cipher.init(opmode, cipherKey, ivSpec, random); |
|
318 |
} |
|
319 |
||
320 |
void implInit(int opmode, Key key, AlgorithmParameters params, |
|
321 |
SecureRandom random) |
|
322 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
323 |
AlgorithmParameterSpec paramSpec = null; |
|
324 |
if (params != null) { |
|
325 |
try { |
|
326 |
paramSpec = params.getParameterSpec(PBEParameterSpec.class); |
|
327 |
} catch (InvalidParameterSpecException ipse) { |
|
7043 | 328 |
throw new InvalidAlgorithmParameterException( |
329 |
"requires PBE parameters"); |
|
2 | 330 |
} |
331 |
} |
|
332 |
implInit(opmode, key, paramSpec, random); |
|
333 |
} |
|
334 |
||
335 |
void implInit(int opmode, Key key, SecureRandom random) |
|
336 |
throws InvalidKeyException { |
|
337 |
try { |
|
338 |
implInit(opmode, key, (AlgorithmParameterSpec) null, random); |
|
339 |
} catch (InvalidAlgorithmParameterException iape) { |
|
340 |
throw new InvalidKeyException("requires PBE parameters"); |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
byte[] implUpdate(byte[] in, int inOff, int inLen) { |
|
345 |
return cipher.update(in, inOff, inLen); |
|
346 |
} |
|
347 |
||
348 |
int implUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff) |
|
349 |
throws ShortBufferException { |
|
350 |
return cipher.update(in, inOff, inLen, out, outOff); |
|
351 |
} |
|
352 |
||
353 |
byte[] implDoFinal(byte[] in, int inOff, int inLen) |
|
354 |
throws IllegalBlockSizeException, BadPaddingException { |
|
355 |
return cipher.doFinal(in, inOff, inLen); |
|
356 |
} |
|
357 |
||
358 |
int implDoFinal(byte[] in, int inOff, int inLen, byte[] out, int outOff) |
|
359 |
throws ShortBufferException, IllegalBlockSizeException, |
|
360 |
BadPaddingException { |
|
361 |
return cipher.doFinal(in, inOff, inLen, out, outOff); |
|
362 |
} |
|
363 |
||
364 |
int implGetKeySize(Key key) throws InvalidKeyException { |
|
365 |
return keySize; |
|
366 |
} |
|
367 |
||
368 |
byte[] implWrap(Key key) throws IllegalBlockSizeException, |
|
369 |
InvalidKeyException { |
|
370 |
return cipher.wrap(key); |
|
371 |
} |
|
372 |
||
373 |
Key implUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, |
|
374 |
int wrappedKeyType) |
|
375 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
376 |
return cipher.unwrap(wrappedKey, wrappedKeyAlgorithm, |
|
377 |
wrappedKeyType); |
|
378 |
} |
|
379 |
||
380 |
public static final class PBEWithSHA1AndDESede extends CipherSpi { |
|
381 |
private final PKCS12PBECipherCore core; |
|
382 |
public PBEWithSHA1AndDESede() throws NoSuchAlgorithmException { |
|
383 |
core = new PKCS12PBECipherCore("DESede", 24); |
|
384 |
} |
|
385 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
|
386 |
throws IllegalBlockSizeException, BadPaddingException { |
|
387 |
return core.implDoFinal(in, inOff, inLen); |
|
388 |
} |
|
389 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
|
390 |
byte[] out, int outOff) |
|
391 |
throws ShortBufferException, IllegalBlockSizeException, |
|
392 |
BadPaddingException { |
|
393 |
return core.implDoFinal(in, inOff, inLen, out, outOff); |
|
394 |
} |
|
395 |
protected int engineGetBlockSize() { |
|
396 |
return core.implGetBlockSize(); |
|
397 |
} |
|
398 |
protected byte[] engineGetIV() { |
|
399 |
return core.implGetIV(); |
|
400 |
} |
|
401 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
|
402 |
return core.implGetKeySize(key); |
|
403 |
} |
|
404 |
protected int engineGetOutputSize(int inLen) { |
|
405 |
return core.implGetOutputSize(inLen); |
|
406 |
} |
|
407 |
protected AlgorithmParameters engineGetParameters() { |
|
408 |
return core.implGetParameters(); |
|
409 |
} |
|
410 |
protected void engineInit(int opmode, Key key, |
|
411 |
AlgorithmParameterSpec params, |
|
412 |
SecureRandom random) |
|
413 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
414 |
core.implInit(opmode, key, params, random); |
|
415 |
} |
|
416 |
protected void engineInit(int opmode, Key key, |
|
417 |
AlgorithmParameters params, |
|
418 |
SecureRandom random) |
|
419 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
420 |
core.implInit(opmode, key, params, random); |
|
421 |
} |
|
422 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
|
423 |
throws InvalidKeyException { |
|
424 |
core.implInit(opmode, key, random); |
|
425 |
} |
|
426 |
protected void engineSetMode(String mode) |
|
427 |
throws NoSuchAlgorithmException { |
|
428 |
core.implSetMode(mode); |
|
429 |
} |
|
430 |
protected void engineSetPadding(String paddingScheme) |
|
431 |
throws NoSuchPaddingException { |
|
432 |
core.implSetPadding(paddingScheme); |
|
433 |
} |
|
434 |
protected Key engineUnwrap(byte[] wrappedKey, |
|
435 |
String wrappedKeyAlgorithm, |
|
436 |
int wrappedKeyType) |
|
437 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
438 |
return core.implUnwrap(wrappedKey, wrappedKeyAlgorithm, |
|
439 |
wrappedKeyType); |
|
440 |
} |
|
441 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
|
442 |
return core.implUpdate(in, inOff, inLen); |
|
443 |
} |
|
444 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
|
445 |
byte[] out, int outOff) |
|
446 |
throws ShortBufferException { |
|
447 |
return core.implUpdate(in, inOff, inLen, out, outOff); |
|
448 |
} |
|
449 |
protected byte[] engineWrap(Key key) |
|
450 |
throws IllegalBlockSizeException, InvalidKeyException { |
|
451 |
return core.implWrap(key); |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
public static final class PBEWithSHA1AndRC2_40 extends CipherSpi { |
|
456 |
private final PKCS12PBECipherCore core; |
|
457 |
public PBEWithSHA1AndRC2_40() throws NoSuchAlgorithmException { |
|
458 |
core = new PKCS12PBECipherCore("RC2", 5); |
|
459 |
} |
|
460 |
protected byte[] engineDoFinal(byte[] in, int inOff, int inLen) |
|
461 |
throws IllegalBlockSizeException, BadPaddingException { |
|
462 |
return core.implDoFinal(in, inOff, inLen); |
|
463 |
} |
|
464 |
protected int engineDoFinal(byte[] in, int inOff, int inLen, |
|
465 |
byte[] out, int outOff) |
|
466 |
throws ShortBufferException, IllegalBlockSizeException, |
|
467 |
BadPaddingException { |
|
468 |
return core.implDoFinal(in, inOff, inLen, out, outOff); |
|
469 |
} |
|
470 |
protected int engineGetBlockSize() { |
|
471 |
return core.implGetBlockSize(); |
|
472 |
} |
|
473 |
protected byte[] engineGetIV() { |
|
474 |
return core.implGetIV(); |
|
475 |
} |
|
476 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
|
477 |
return core.implGetKeySize(key); |
|
478 |
} |
|
479 |
protected int engineGetOutputSize(int inLen) { |
|
480 |
return core.implGetOutputSize(inLen); |
|
481 |
} |
|
482 |
protected AlgorithmParameters engineGetParameters() { |
|
483 |
return core.implGetParameters(); |
|
484 |
} |
|
485 |
protected void engineInit(int opmode, Key key, |
|
486 |
AlgorithmParameterSpec params, |
|
487 |
SecureRandom random) |
|
488 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
489 |
core.implInit(opmode, key, params, random); |
|
490 |
} |
|
491 |
protected void engineInit(int opmode, Key key, |
|
492 |
AlgorithmParameters params, |
|
493 |
SecureRandom random) |
|
494 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
|
495 |
core.implInit(opmode, key, params, random); |
|
496 |
} |
|
497 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
|
498 |
throws InvalidKeyException { |
|
499 |
core.implInit(opmode, key, random); |
|
500 |
} |
|
501 |
protected void engineSetMode(String mode) |
|
502 |
throws NoSuchAlgorithmException { |
|
503 |
core.implSetMode(mode); |
|
504 |
} |
|
505 |
protected void engineSetPadding(String paddingScheme) |
|
506 |
throws NoSuchPaddingException { |
|
507 |
core.implSetPadding(paddingScheme); |
|
508 |
} |
|
509 |
protected Key engineUnwrap(byte[] wrappedKey, |
|
510 |
String wrappedKeyAlgorithm, |
|
511 |
int wrappedKeyType) |
|
512 |
throws InvalidKeyException, NoSuchAlgorithmException { |
|
513 |
return core.implUnwrap(wrappedKey, wrappedKeyAlgorithm, |
|
514 |
wrappedKeyType); |
|
515 |
} |
|
516 |
protected byte[] engineUpdate(byte[] in, int inOff, int inLen) { |
|
517 |
return core.implUpdate(in, inOff, inLen); |
|
518 |
} |
|
519 |
protected int engineUpdate(byte[] in, int inOff, int inLen, |
|
520 |
byte[] out, int outOff) |
|
521 |
throws ShortBufferException { |
|
522 |
return core.implUpdate(in, inOff, inLen, out, outOff); |
|
523 |
} |
|
524 |
protected byte[] engineWrap(Key key) |
|
525 |
throws IllegalBlockSizeException, InvalidKeyException { |
|
526 |
return core.implWrap(key); |
|
527 |
} |
|
528 |
} |
|
529 |
} |