@@ -126,18 +126,23 @@ public static SecretKey generateSecretKey(String alg, int keySize)
126
126
* this is thrown with the original {@code UnsupportedEncodingException}
127
127
* as the cause. (NOTE: This should never happen as "UTF-8" is supposed to
128
128
* be a common encoding supported by all Java implementations. Support
129
- * for it is usually in rt.jar.)
129
+ * for it is usually in rt.jar.) This exception is also thrown if the
130
+ * requested {@code keySize} parameter exceeds the length of the number of
131
+ * bytes provded in the {@code keyDerivationKey} parameter.
130
132
* @throws InvalidKeyException Likely indicates a coding error. Should not happen.
131
133
* @throws EncryptionException Throw for some precondition violations.
132
- * @deprecated Use{@code KeyDerivationFunction} instead. This method will be removed as of
133
- * ESAPI release 2.3 so if you are using this, please change your code.
134
+ * @deprecated Use same method in {@code KeyDerivationFunction} instead. This method will be <b>removed</b> as of
135
+ * ESAPI release 2.3 so if you are using this, please CHANGE YOUR CODE. Note that the replacement
136
+ * is not a static method, so create your own wrapper if you wish, but this will soon disappear.
134
137
*/
135
138
@ Deprecated
136
139
public static SecretKey computeDerivedKey (SecretKey keyDerivationKey , int keySize , String purpose )
137
140
throws NoSuchAlgorithmException , InvalidKeyException , EncryptionException
138
141
{
139
- // These really should be turned into actual runtime checks and an
140
- // IllegalArgumentException should be thrown if they are violated.
142
+ // Fingers cross; maybe this will help.
143
+ logger .warning (Logger .SECURITY_AUDIT ,
144
+ "Your code is using the deprecated CryptoHelper.computeDerivedKey() method which will be removed next release" );
145
+
141
146
if ( keyDerivationKey == null ) {
142
147
throw new IllegalArgumentException ("Key derivation key cannot be null." );
143
148
}
@@ -159,6 +164,9 @@ public static SecretKey computeDerivedKey(SecretKey keyDerivationKey, int keySiz
159
164
// DISCUSS: Should we use HmacSHA1 (what we were using) or the HMAC defined by
160
165
// Encryptor.KDF.PRF instead? Either way, this is not compatible with
161
166
// previous ESAPI versions. JavaEncryptor doesn't use this any longer.
167
+ // ANSWER: This is deprecated and will be removed in 2.3.0.0, so it really matter
168
+ // that much. However, Since the property Encryptor.KDF.PRF is (and has
169
+ // been) "HMacSHA256". changing this could unintentionally break code.
162
170
KeyDerivationFunction kdf = new KeyDerivationFunction (
163
171
KeyDerivationFunction .PRF_ALGORITHMS .HmacSHA1 );
164
172
return kdf .computeDerivedKey (keyDerivationKey , keySize , purpose );
@@ -260,7 +268,8 @@ public static boolean isCipherTextMACvalid(SecretKey sk, CipherText ct)
260
268
{
261
269
if ( CryptoHelper .isMACRequired ( ct ) ) {
262
270
try {
263
- SecretKey authKey = CryptoHelper .computeDerivedKey ( sk , ct .getKeySize (), "authenticity" );
271
+ KeyDerivationFunction kdf = new KeyDerivationFunction ( ct .getKDF_PRF () );
272
+ SecretKey authKey = kdf .computeDerivedKey (sk , ct .getKeySize (), "authenticity" );
264
273
boolean validMAC = ct .validateMAC ( authKey );
265
274
return validMAC ;
266
275
} catch (Exception ex ) {
0 commit comments