Class CtrCryptoOutputStream

java.lang.Object
java.io.OutputStream
org.apache.commons.crypto.stream.CryptoOutputStream
org.apache.commons.crypto.stream.CtrCryptoOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Channel, WritableByteChannel

CtrCryptoOutputStream encrypts data. It is not thread-safe. AES CTR mode is required in order to ensure that the plain text and cipher text have a 1:1 mapping. The encryption is buffer based. The key points of the encryption are (1) calculating counter and (2) padding through stream position.

counter = base + pos/(algorithm blocksize); padding = pos%(algorithm blocksize);

The underlying stream offset is maintained as state.

This class should only be used with blocking sinks. Using this class to wrap a non-blocking sink may lead to high CPU usage.