author | vinnie |
Thu, 11 Apr 2013 17:57:08 +0100 | |
changeset 16909 | 78a1749a43e2 |
parent 15010 | ec6b49ce42b1 |
permissions | -rw-r--r-- |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
1 |
/* |
15010 | 2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
4 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
10 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
15 |
* accompanied this code). |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
16 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
20 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
23 |
* questions. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
24 |
*/ |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
25 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
26 |
package com.sun.crypto.provider; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
27 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
28 |
import java.security.*; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
29 |
import java.security.spec.*; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
30 |
import javax.crypto.*; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
31 |
import javax.crypto.spec.*; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
32 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
33 |
/** |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
34 |
* This class represents password-based encryption as defined by the PKCS #5 |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
35 |
* standard. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
36 |
* These algorithms implement PBE with HmacSHA1/HmacSHA2-family and AES-CBC. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
37 |
* Padding is done as described in PKCS #5. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
38 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
39 |
* @author Jan Luehe |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
40 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
41 |
* |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
42 |
* @see javax.crypto.Cipher |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
43 |
*/ |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
44 |
abstract class PBES2Core extends CipherSpi { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
45 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
46 |
private static final int DEFAULT_SALT_LENGTH = 20; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
47 |
private static final int DEFAULT_COUNT = 4096; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
48 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
49 |
// the encapsulated cipher |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
50 |
private final CipherCore cipher; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
51 |
private final int keyLength; // in bits |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
52 |
private final int blkSize; // in bits |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
53 |
private final PBKDF2Core kdf; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
54 |
private final String pbeAlgo; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
55 |
private final String cipherAlgo; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
56 |
private int iCount = DEFAULT_COUNT; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
57 |
private byte[] salt = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
58 |
private IvParameterSpec ivSpec = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
59 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
60 |
/** |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
61 |
* Creates an instance of PBE Scheme 2 according to the selected |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
62 |
* password-based key derivation function and encryption scheme. |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
63 |
*/ |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
64 |
PBES2Core(String kdfAlgo, String cipherAlgo, int keySize) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
65 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
66 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
67 |
this.cipherAlgo = cipherAlgo; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
68 |
keyLength = keySize * 8; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
69 |
pbeAlgo = "PBEWith" + kdfAlgo + "And" + cipherAlgo + "_" + keyLength; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
70 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
71 |
if (cipherAlgo.equals("AES")) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
72 |
blkSize = AESConstants.AES_BLOCK_SIZE; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
73 |
cipher = new CipherCore(new AESCrypt(), blkSize); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
74 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
75 |
switch(kdfAlgo) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
76 |
case "HmacSHA1": |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
77 |
kdf = new PBKDF2Core.HmacSHA1(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
78 |
break; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
79 |
case "HmacSHA224": |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
80 |
kdf = new PBKDF2Core.HmacSHA224(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
81 |
break; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
82 |
case "HmacSHA256": |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
83 |
kdf = new PBKDF2Core.HmacSHA256(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
84 |
break; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
85 |
case "HmacSHA384": |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
86 |
kdf = new PBKDF2Core.HmacSHA384(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
87 |
break; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
88 |
case "HmacSHA512": |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
89 |
kdf = new PBKDF2Core.HmacSHA512(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
90 |
break; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
91 |
default: |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
92 |
throw new NoSuchAlgorithmException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
93 |
"No Cipher implementation for " + kdfAlgo); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
94 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
95 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
96 |
throw new NoSuchAlgorithmException("No Cipher implementation for " + |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
97 |
pbeAlgo); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
98 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
99 |
cipher.setMode("CBC"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
100 |
cipher.setPadding("PKCS5Padding"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
101 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
102 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
103 |
protected void engineSetMode(String mode) throws NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
104 |
if ((mode != null) && (!mode.equalsIgnoreCase("CBC"))) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
105 |
throw new NoSuchAlgorithmException("Invalid cipher mode: " + mode); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
106 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
107 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
108 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
109 |
protected void engineSetPadding(String paddingScheme) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
110 |
throws NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
111 |
if ((paddingScheme != null) && |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
112 |
(!paddingScheme.equalsIgnoreCase("PKCS5Padding"))) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
113 |
throw new NoSuchPaddingException("Invalid padding scheme: " + |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
114 |
paddingScheme); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
115 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
116 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
117 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
118 |
protected int engineGetBlockSize() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
119 |
return blkSize; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
120 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
121 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
122 |
protected int engineGetOutputSize(int inputLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
123 |
return cipher.getOutputSize(inputLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
124 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
125 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
126 |
protected byte[] engineGetIV() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
127 |
return cipher.getIV(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
128 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
129 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
130 |
protected AlgorithmParameters engineGetParameters() { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
131 |
AlgorithmParameters params = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
132 |
if (salt == null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
133 |
// generate random salt and use default iteration count |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
134 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
15010 | 135 |
SunJCE.getRandom().nextBytes(salt); |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
136 |
iCount = DEFAULT_COUNT; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
137 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
138 |
if (ivSpec == null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
139 |
// generate random IV |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
140 |
byte[] ivBytes = new byte[blkSize]; |
15010 | 141 |
SunJCE.getRandom().nextBytes(ivBytes); |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
142 |
ivSpec = new IvParameterSpec(ivBytes); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
143 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
144 |
PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iCount, ivSpec); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
145 |
try { |
16909
78a1749a43e2
7171982: Cipher getParameters() throws RuntimeException: Cannot find SunJCE provider
vinnie
parents:
15010
diff
changeset
|
146 |
params = AlgorithmParameters.getInstance(pbeAlgo, |
78a1749a43e2
7171982: Cipher getParameters() throws RuntimeException: Cannot find SunJCE provider
vinnie
parents:
15010
diff
changeset
|
147 |
SunJCE.getInstance()); |
78a1749a43e2
7171982: Cipher getParameters() throws RuntimeException: Cannot find SunJCE provider
vinnie
parents:
15010
diff
changeset
|
148 |
params.init(pbeSpec); |
14405
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
149 |
} catch (NoSuchAlgorithmException nsae) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
150 |
// should never happen |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
151 |
throw new RuntimeException("SunJCE called, but not configured"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
152 |
} catch (InvalidParameterSpecException ipse) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
153 |
// should never happen |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
154 |
throw new RuntimeException("PBEParameterSpec not supported"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
155 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
156 |
return params; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
157 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
158 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
159 |
protected void engineInit(int opmode, Key key, SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
160 |
throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
161 |
try { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
162 |
engineInit(opmode, key, (AlgorithmParameterSpec) null, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
163 |
} catch (InvalidAlgorithmParameterException ie) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
164 |
InvalidKeyException ike = |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
165 |
new InvalidKeyException("requires PBE parameters"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
166 |
ike.initCause(ie); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
167 |
throw ike; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
168 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
169 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
170 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
171 |
protected void engineInit(int opmode, Key key, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
172 |
AlgorithmParameterSpec params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
173 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
174 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
175 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
176 |
if ((key == null) || |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
177 |
(key.getEncoded() == null) || |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
178 |
!(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
179 |
throw new InvalidKeyException("Missing password"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
180 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
181 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
182 |
// TBD: consolidate the salt, ic and IV parameter checks below |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
183 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
184 |
// Extract salt and iteration count from the key, if present |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
185 |
if (key instanceof javax.crypto.interfaces.PBEKey) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
186 |
salt = ((javax.crypto.interfaces.PBEKey)key).getSalt(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
187 |
if (salt != null && salt.length < 8) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
188 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
189 |
"Salt must be at least 8 bytes long"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
190 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
191 |
iCount = ((javax.crypto.interfaces.PBEKey)key).getIterationCount(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
192 |
if (iCount == 0) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
193 |
iCount = DEFAULT_COUNT; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
194 |
} else if (iCount < 0) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
195 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
196 |
"Iteration count must be a positive number"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
197 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
198 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
199 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
200 |
// Extract salt, iteration count and IV from the params, if present |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
201 |
if (params == null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
202 |
if (salt == null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
203 |
// generate random salt and use default iteration count |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
204 |
salt = new byte[DEFAULT_SALT_LENGTH]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
205 |
random.nextBytes(salt); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
206 |
iCount = DEFAULT_COUNT; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
207 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
208 |
if ((opmode == Cipher.ENCRYPT_MODE) || |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
209 |
(opmode == Cipher.WRAP_MODE)) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
210 |
// generate random IV |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
211 |
byte[] ivBytes = new byte[blkSize]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
212 |
random.nextBytes(ivBytes); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
213 |
ivSpec = new IvParameterSpec(ivBytes); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
214 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
215 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
216 |
if (!(params instanceof PBEParameterSpec)) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
217 |
throw new InvalidAlgorithmParameterException |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
218 |
("Wrong parameter type: PBE expected"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
219 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
220 |
// salt and iteration count from the params take precedence |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
221 |
byte[] specSalt = ((PBEParameterSpec) params).getSalt(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
222 |
if (specSalt != null && specSalt.length < 8) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
223 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
224 |
"Salt must be at least 8 bytes long"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
225 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
226 |
salt = specSalt; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
227 |
int specICount = ((PBEParameterSpec) params).getIterationCount(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
228 |
if (specICount == 0) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
229 |
specICount = DEFAULT_COUNT; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
230 |
} else if (specICount < 0) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
231 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
232 |
"Iteration count must be a positive number"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
233 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
234 |
iCount = specICount; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
235 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
236 |
AlgorithmParameterSpec specParams = |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
237 |
((PBEParameterSpec) params).getParameterSpec(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
238 |
if (specParams != null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
239 |
if (specParams instanceof IvParameterSpec) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
240 |
ivSpec = (IvParameterSpec)specParams; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
241 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
242 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
243 |
"Wrong parameter type: IV expected"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
244 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
245 |
} else if ((opmode == Cipher.ENCRYPT_MODE) || |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
246 |
(opmode == Cipher.WRAP_MODE)) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
247 |
// generate random IV |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
248 |
byte[] ivBytes = new byte[blkSize]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
249 |
random.nextBytes(ivBytes); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
250 |
ivSpec = new IvParameterSpec(ivBytes); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
251 |
} else { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
252 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
253 |
"Missing parameter type: IV expected"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
254 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
255 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
256 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
257 |
SecretKeySpec cipherKey = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
258 |
byte[] derivedKey = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
259 |
byte[] passwdBytes = key.getEncoded(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
260 |
char[] passwdChars = new char[passwdBytes.length]; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
261 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
262 |
for (int i=0; i<passwdChars.length; i++) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
263 |
passwdChars[i] = (char) (passwdBytes[i] & 0x7f); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
264 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
265 |
PBEKeySpec pbeSpec = |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
266 |
new PBEKeySpec(passwdChars, salt, iCount, blkSize * 8); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
267 |
// password char[] was cloned in PBEKeySpec constructor, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
268 |
// so we can zero it out here |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
269 |
java.util.Arrays.fill(passwdChars, ' '); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
270 |
java.util.Arrays.fill(passwdBytes, (byte)0x00); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
271 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
272 |
SecretKey s = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
273 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
274 |
try { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
275 |
s = kdf.engineGenerateSecret(pbeSpec); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
276 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
277 |
} catch (InvalidKeySpecException ikse) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
278 |
InvalidKeyException ike = |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
279 |
new InvalidKeyException("Cannot construct PBE key"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
280 |
ike.initCause(ikse); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
281 |
throw ike; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
282 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
283 |
derivedKey = s.getEncoded(); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
284 |
cipherKey = new SecretKeySpec(derivedKey, cipherAlgo); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
285 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
286 |
// initialize the underlying cipher |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
287 |
cipher.init(opmode, cipherKey, ivSpec, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
288 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
289 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
290 |
protected void engineInit(int opmode, Key key, AlgorithmParameters params, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
291 |
SecureRandom random) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
292 |
throws InvalidKeyException, InvalidAlgorithmParameterException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
293 |
AlgorithmParameterSpec pbeSpec = null; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
294 |
if (params != null) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
295 |
try { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
296 |
pbeSpec = params.getParameterSpec(PBEParameterSpec.class); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
297 |
} catch (InvalidParameterSpecException ipse) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
298 |
throw new InvalidAlgorithmParameterException( |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
299 |
"Wrong parameter type: PBE expected"); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
300 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
301 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
302 |
engineInit(opmode, key, pbeSpec, random); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
303 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
304 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
305 |
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
306 |
return cipher.update(input, inputOffset, inputLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
307 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
308 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
309 |
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
310 |
byte[] output, int outputOffset) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
311 |
throws ShortBufferException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
312 |
return cipher.update(input, inputOffset, inputLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
313 |
output, outputOffset); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
314 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
315 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
316 |
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
317 |
throws IllegalBlockSizeException, BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
318 |
return cipher.doFinal(input, inputOffset, inputLen); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
319 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
320 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
321 |
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
322 |
byte[] output, int outputOffset) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
323 |
throws ShortBufferException, IllegalBlockSizeException, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
324 |
BadPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
325 |
return cipher.doFinal(input, inputOffset, inputLen, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
326 |
output, outputOffset); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
327 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
328 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
329 |
protected int engineGetKeySize(Key key) throws InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
330 |
return keyLength; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
331 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
332 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
333 |
protected byte[] engineWrap(Key key) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
334 |
throws IllegalBlockSizeException, InvalidKeyException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
335 |
return cipher.wrap(key); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
336 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
337 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
338 |
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
339 |
int wrappedKeyType) |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
340 |
throws InvalidKeyException, NoSuchAlgorithmException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
341 |
byte[] encodedKey; |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
342 |
return cipher.unwrap(wrappedKey, wrappedKeyAlgorithm, |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
343 |
wrappedKeyType); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
344 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
345 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
346 |
public static final class HmacSHA1AndAES_128 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
347 |
public HmacSHA1AndAES_128() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
348 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
349 |
super("HmacSHA1", "AES", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
350 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
351 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
352 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
353 |
public static final class HmacSHA224AndAES_128 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
354 |
public HmacSHA224AndAES_128() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
355 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
356 |
super("HmacSHA224", "AES", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
357 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
358 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
359 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
360 |
public static final class HmacSHA256AndAES_128 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
361 |
public HmacSHA256AndAES_128() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
362 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
363 |
super("HmacSHA256", "AES", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
364 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
365 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
366 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
367 |
public static final class HmacSHA384AndAES_128 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
368 |
public HmacSHA384AndAES_128() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
369 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
370 |
super("HmacSHA384", "AES", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
371 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
372 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
373 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
374 |
public static final class HmacSHA512AndAES_128 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
375 |
public HmacSHA512AndAES_128() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
376 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
377 |
super("HmacSHA512", "AES", 16); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
378 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
379 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
380 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
381 |
public static final class HmacSHA1AndAES_256 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
382 |
public HmacSHA1AndAES_256() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
383 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
384 |
super("HmacSHA1", "AES", 32); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
385 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
386 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
387 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
388 |
public static final class HmacSHA224AndAES_256 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
389 |
public HmacSHA224AndAES_256() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
390 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
391 |
super("HmacSHA224", "AES", 32); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
392 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
393 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
394 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
395 |
public static final class HmacSHA256AndAES_256 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
396 |
public HmacSHA256AndAES_256() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
397 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
398 |
super("HmacSHA256", "AES", 32); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
399 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
400 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
401 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
402 |
public static final class HmacSHA384AndAES_256 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
403 |
public HmacSHA384AndAES_256() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
404 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
405 |
super("HmacSHA384", "AES", 32); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
406 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
407 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
408 |
|
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
409 |
public static final class HmacSHA512AndAES_256 extends PBES2Core { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
410 |
public HmacSHA512AndAES_256() |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
411 |
throws NoSuchAlgorithmException, NoSuchPaddingException { |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
412 |
super("HmacSHA512", "AES", 32); |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
413 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
414 |
} |
e7fff80005c1
6383200: PBE: need new algorithm support in password based encryption
vinnie
parents:
diff
changeset
|
415 |
} |