Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialized.
All input.remaining() bytes starting at
input.position() are processed.
If an AEAD mode such as GCM/CCM is being used, the authentication
tag is appended in the case of encryption, or verified in the
case of decryption.
The result is stored in the output buffer.
Upon return, the input buffer's position will be equal
to its limit; its limit will not have changed. The output buffer's
position will have advanced by n, where n is the value returned
by this method; the output buffer's limit will not have changed.
If output.remaining() bytes are insufficient to
hold the result, a ShortBufferException is thrown.
Upon finishing, this method resets this cipher object to the state
it was in when previously initialized via a call to
engineInit.
That is, the object is reset and available to encrypt or decrypt
(depending on the operation mode that was specified in the call to
engineInit) more data.
Note: if any exception is thrown, this cipher object may need to be reset before it can be used again.
Subclasses should consider overriding this method if they can process ByteBuffers more efficiently than byte arrays.
input | the input ByteBuffer | |
output | the output ByteByffer |
output
IllegalBlockSizeException | if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided. | |
ShortBufferException | if there is insufficient space in the output buffer | |
BadPaddingException | if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes | |
AEADBadTagException | if this cipher is decrypting in an AEAD mode (such as GCM/CCM), and the received authentication tag does not match the calculated value | |
NullPointerException | if either parameter is null |
Diagram: Cipher