hw-security / de.cotech.hw.util.stream

Package de.cotech.hw.util.stream

Types

Name Summary
DecryptingFileInputStream

open class DecryptingFileInputStream :InputStream

An InputStream that decrypts data with a ByteSecret. See DecryptingFileInputStream.

EncryptingFileOutputStream

open class EncryptingFileOutputStream :OutputStream

An OutputStream that encrypts data with a ByteSecret.

ByteSecret secret = SecretGenerator.getInstance().createRandom(32);
  EncryptingFileOutputStream efos = new EncryptingFileOutputStream(new File("filename.encrypted"), secret);
  try {
      efos.write("hello!\n");
  } finally {
      efos.close();
  }
  BufferedReader reader = new BufferedReader(new DecryptingFileOutputStream(new File("filename.encrypted"), secret));
  try {
      String line = reader.readLine();
      assertEquals("hello!\n", line);
  } finally {
      reader.close();
  }

Internally, this uses AES-GCM for authenticated encryption. The randomly generated nonce is stored as part of the file.