Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
The cipher is initialized for one of the following four operations:
encryption, decryption, key wrapping or key unwrapping, depending
on the value of opmode.
If this cipher requires any algorithm parameters and
params is null, the underlying cipher implementation is
supposed to generate the required parameters itself (using
provider-specific default or random values) if it is being
initialized for encryption or key wrapping, and raise an
InvalidAlgorithmParameterException if it is being
initialized for decryption or key unwrapping.
The generated parameters can be retrieved using
getParameters or
getIV (if the parameter is an IV).
If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.
If this cipher (including its underlying feedback or padding scheme)
requires any random bytes (e.g., for parameter generation), it will get
them from random.
Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.
opmode | the operation mode of this cipher (this is one of the
following: ENCRYPT_MODE,
DECRYPT_MODE, WRAP_MODE
or UNWRAP_MODE) | |
key | the encryption key | |
params | the algorithm parameters | |
random | the source of randomness |
InvalidKeyException | if the given key is inappropriate for initializing this cipher, or its keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files). | |
InvalidAlgorithmParameterException | if the given algorithm
parameters are inappropriate for this cipher,
or this cipher requires
algorithm parameters and params is null, or the given
algorithm parameters imply a cryptographic strength that would exceed
the legal limits (as determined from the configured jurisdiction
policy files). |
Diagram: Cipher