private static void decryptFile(
      StreamingAead streamingAead, Path inputFile, Path outputFile, byte[] associatedData)
      throws GeneralSecurityException, IOException {
    try (ReadableByteChannel plaintextChannel =
            streamingAead.newDecryptingChannel(
                FileChannel.open(inputFile, StandardOpenOption.READ), associatedData);
        FileChannel outputChannel =
            FileChannel.open(outputFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
      ByteBuffer byteBuffer = ByteBuffer.allocate(BLOCK_SIZE_IN_BYTES);
      while (true) {
        int read = plaintextChannel.read(byteBuffer);
        if (read <= 0) {
          return;
        }
        byteBuffer.flip();
        while (byteBuffer.hasRemaining()) {
          outputChannel.write(byteBuffer);
        }
        byteBuffer.clear();
      }
    }
  }
A command-line utility for encrypting files with Streaming AEAD.

<p>It loads cleartext keys from disk - this is not recommended!

<p>It requires the following arguments:

<ul>
  <li>mode: Can be "encrypt" or "decrypt" to encrypt/decrypt the input to the output.
  <li>key-file: Read the key material from this file.
  <li>input-file: Read the input from this file.
  <li>output-file: Write the result to this file.
  <li>[optional] associated-data: Associated data used for the encryption or decryption.
java_src/examples/streamingaead/StreamingAeadExample.java