public class EncryptedAttachmentInputStream
extends java.io.FilterInputStream
An EncryptedAttachmentInputStream handles reading AES encrypted data from disk, first reading the attachment file's header to determine the IV and checking the on-disk version is readable. A CipherInputStream is used to decrypt the data read via read() methods.
This class adheres strictly to the semantics, especially the failure semantics, of its ancestor classes java.io.FilterInputStream and java.io.InputStream. This class has exactly those methods specified in its ancestor classes, and overrides them all. Moreover, this class catches all exceptions that are not thrown by its ancestor classes. In particular, the skip method skips, and the available method counts only data that have been processed by the encapsulated Cipher.
It is crucial for a programmer using this class not to use methods that are not defined or overriden in this class (such as a new method or constructor that is later added to one of the super classes), because the design and implementation of those methods are unlikely to have considered security impact with regard to CipherInputStream.
The data format read by this class is written by EncryptedAttachmentOutputStream, and is:
Header: 1-byte : version number, 1 16-byte: initialisation vector Body: AES CBC Encrypted file content.
Constructor and Description |
---|
EncryptedAttachmentInputStream(java.io.InputStream in,
byte[] key)
Creates an input stream with a key.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
long |
skip(long n) |
public EncryptedAttachmentInputStream(java.io.InputStream in, byte[] key) throws java.security.InvalidKeyException, java.io.IOException
Creates an input stream with a key.
An IV is not required as the on-disk format contains this.
This constructor reads bytes from the in parameter in order to read the header.
Note: if the specified input stream is null, a NullPointerException is thrown as the constructor tries to read from the passed input stream.
in
- the input stream object.key
- the encryption key to use. Length must be supported by underlying
JCE implementation.java.security.InvalidKeyException
- if key is wrong sizejava.io.IOException
- on I/O exceptionspublic int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.FilterInputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterInputStream
java.io.IOException
public boolean markSupported()
markSupported
in class java.io.FilterInputStream