hwsecurity-openpgp / de.cotech.hw.openpgp.util / EncryptingFileOutputStream /

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.

See also

Name Summary
de.cotech.hw.openpgp.util.DecryptingFileInputStream

Constructors

Name Summary
EncryptingFileOutputStream open fun EncryptingFileOutputStream(file: File, byteSecret: ByteSecret)

Functions

Name Summary
close open fun close()
open fun close()
flush open fun flush()
open fun flush()
write open fun write(buffer: Array<Byte>)
open fun write(i: Int)
abstract fun write(p: Int)
open fun write(buffer: Array<Byte>, off: Int, len: Int)