Class EncryptionOutputStream

  • All Implemented Interfaces:
    java.io.Closeable , java.io.Flushable , java.lang.AutoCloseable

    
    public class EncryptionOutputStream
    extends FilterOutputStream
                        

    This class provides a wrapper for an OutputStream that encrypts or decrypts the bytes as they are read.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      EncryptionOutputStream(OutputStream out, boolean encrypt, Array<byte> encryptionKey)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      void write(int b)
      void write(@NonNull() Array<byte> b)
      void write(@NonNull() Array<byte> b, int off, int len)
      void flush() DO NOT RELY ON THIS METHOD.
      void close() This method ensures all encrypted/decrypted bytes are written to the OutputStream, then the OutputStream is closed and resources are freed.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EncryptionOutputStream

        EncryptionOutputStream(OutputStream out, boolean encrypt, Array<byte> encryptionKey)
        Parameters:
        out - The OutputStream that will be encrypted/decrypted.
        encrypt - True means the OutputStream will be encrypted.
        encryptionKey - The key which is used for encryption/decryption.
    • Method Detail

      • write

         void write(int b)
      • write

         void write(@NonNull() Array<byte> b)
      • write

         void write(@NonNull() Array<byte> b, int off, int len)
      • flush

         void flush()

        DO NOT RELY ON THIS METHOD. Since the stream is being encrypted/decrypted, it is not possible to ensure all bytes have been written. The cipher may not have enough bytes to complete a block in which case the corresponding encrypted/decrypted bytes cannot be flushed. If you need to ensure all bytes are written there is no choice but to finalize the stream by calling close().

      • close

         void close()

        This method ensures all encrypted/decrypted bytes are written to the OutputStream, then the OutputStream is closed and resources are freed.