in encryption/src/main/java/org/apache/solr/encryption/crypto/DecryptingInputStream.java [94:128]
public DecryptingInputStream(InputStream inputStream,
long position,
byte[] iv,
byte[] key,
AesCtrEncrypterFactory factory,
int bufferCapacity)
throws IOException {
if (position < 0) {
throw new IllegalArgumentException("Invalid position " + position);
}
this.inputStream = inputStream;
assert bufferCapacity % AES_BLOCK_SIZE == 0;
inBuffer = new byte[bufferCapacity];
outBuffer = new byte[bufferCapacity + AES_BLOCK_SIZE];
oneByteBuf = new byte[1];
long counter;
if (position == 0) {
// Read the IV at the beginning of the input stream.
iv = new byte[IV_LENGTH];
int n = inputStream.read(iv, 0, iv.length);
if (n != iv.length) {
throw new IOException("Missing IV");
}
counter = 0;
} else if (iv == null) {
throw new IllegalArgumentException("IV must be provided when position is not zero");
} else {
counter = position / AES_BLOCK_SIZE;
padding = (int) (position & AES_BLOCK_SIZE_MOD_MASK);
inPos = padding;
}
this.iv = iv;
encrypter = factory.create(key, iv);
encrypter.init(counter);
}