/** * Does final encryption of the last data. * * @throws IOException if an I/O error occurs. */ @Override protected void encryptFinal() throws IOException { // The same as the normal encryption for Counter mode encrypt(); }
encryptBuffer(outBuffer); inBuffer.clear(); outBuffer.flip(); resetCipher();
private static OutputStream createApacheEncryptedStream(OutputStream output, KeyMaterial keyMaterial) throws IOException { SecretKey secretKey = keyMaterial.getSecretKey(); byte[] iv = keyMaterial.getIv(); return new CtrCryptoOutputStream(PROPS, output, secretKey.getEncoded(), iv); }
/** * Constructs a {@link CtrCryptoOutputStream}. * * @param output the output stream. * @param cipher the CryptoCipher instance. * @param bufferSize the bufferSize. * @param key crypto key for the cipher. * @param iv Initialization vector for the cipher. * @param streamOffset the start offset in the data. * @throws IOException if an I/O error occurs. */ protected CtrCryptoOutputStream(Output output, CryptoCipher cipher, int bufferSize, byte[] key, byte[] iv, long streamOffset) throws IOException { super(output, cipher, bufferSize, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv)); CryptoInputStream.checkStreamCipher(cipher); this.streamOffset = streamOffset; this.initIV = iv.clone(); this.iv = iv.clone(); resetCipher(); }