8265500: Some impls of javax.crypto.Cipher.init() do not throw UnsupportedOperationExc for unsupported modes

Reviewed-by: xuelei
This commit is contained in:
Valerie Peng 2021-06-17 23:27:54 +00:00
parent 9130b8a9d7
commit 80dc262e81
8 changed files with 302 additions and 53 deletions

View file

@ -179,14 +179,16 @@ public final class ARCFOURCipher extends CipherSpi {
init(opmode, key);
}
// init method. Check opmode and key, then call init(byte[]).
// init method. Check key, then call init(byte[]).
private void init(int opmode, Key key) throws InvalidKeyException {
// Cipher.init() already checks opmode to be:
// ENCRYPT_MODE/DECRYPT_MODE/WRAP_MODE/UNWRAP_MODE
if (lastKey != null) {
Arrays.fill(lastKey, (byte)0);
}
if ((opmode < Cipher.ENCRYPT_MODE) || (opmode > Cipher.UNWRAP_MODE)) {
throw new InvalidKeyException("Unknown opmode: " + opmode);
}
lastKey = getEncodedKey(key);
init(lastKey);
}