// and the initialization vector
encryptingCipher.init(Cipher.ENCRYPT_MODE, this.secretKey,
new IvParameterSpec(this.initVector));
break;
default:
throw new BuilderException("Unrecognized mode");
}
// make an AES cipher that we can use for decryption
this.decryptingCipher = Cipher.getInstance(this.algModePadding);
// initialize the decrypting cipher
switch (this.mode) {
case ECB:
// Initialize the cipher using the secret key -
// ECB does NOT use an initialization vector
decryptingCipher.init(Cipher.DECRYPT_MODE, secretKey);
break;
case CBC:
case OFB:
case CFB:
case CTR:
// Initialize the cipher using the secret key of this class
// and the initialization vector
decryptingCipher.init(
Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(initVector));
break;
default:
throw new BuilderException("Unrecognized mode");
}
// Catch all exceptions
} catch (Exception e) {
// Propagate the exception up using BuilderException
throw new BuilderException("Building AESKeyVersion failed", e);
}
}