Initializes this cipher with a key 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 that cannot be
derived from the given key, 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
InvalidKeyException 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 | |
random | the source of randomness |
InvalidKeyException | if the given key is inappropriate for initializing this cipher, or requires algorithm parameters that cannot be determined from the given key, or if the given key has a keysize that exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files). | |
UnsupportedOperationException | if (@code opmode} is
WRAP_MODE or UNWRAP_MODE but the mode is not implemented
by the underlying CipherSpi. |
Diagram: Cipher