org.cryptonode.jncryptor
Class AES256JNCryptorInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.cryptonode.jncryptor.AES256JNCryptorInputStream
All Implemented Interfaces:
Closeable

public class AES256JNCryptorInputStream
extends InputStream

Reads RNCryptor-format data in a stream fashion. This class only supports the v3 data format. The entire stream must be read in order to trigger the validation of the HMAC value.

Since:
1.1.0

Constructor Summary
AES256JNCryptorInputStream(InputStream in, char[] password)
          Creates an input stream for password-encrypted data.
AES256JNCryptorInputStream(InputStream in, SecretKey decryptionKey, SecretKey hmacKey)
          Creates an input stream for key-encrypted data.
 
Method Summary
 void close()
          Closes the underlying input stream.
 boolean markSupported()
          Mark and reset methods are not supported in this input stream.
 int read()
          Reads the next byte from the input stream.
 int read(byte[] b)
          The read(b) method for class AES256JNCryptorInputStream has the same effect as:
 int read(byte[] b, int off, int len)
          Reads a number of bytes into the byte array.
 
Methods inherited from class java.io.InputStream
available, mark, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AES256JNCryptorInputStream

public AES256JNCryptorInputStream(InputStream in,
                                  char[] password)
Creates an input stream for password-encrypted data.

Parameters:
in - the InputStream to read
password - the password

AES256JNCryptorInputStream

public AES256JNCryptorInputStream(InputStream in,
                                  SecretKey decryptionKey,
                                  SecretKey hmacKey)
Creates an input stream for key-encrypted data.

Parameters:
in - the InputStream to read
decryptionKey - the key to decrypt with
hmacKey - the key to calculate the HMAC with
Method Detail

markSupported

public boolean markSupported()
Mark and reset methods are not supported in this input stream.

Overrides:
markSupported in class InputStream
Returns:
false

read

public int read()
         throws IOException,
                StreamIntegrityException
Reads the next byte from the input stream. If this is the last byte in the stream (determined by peeking ahead to the next byte), the value of the HMAC is verified. If the verification fails an exception is thrown.

Specified by:
read in class InputStream
Returns:
the next byte from the input stream, or -1 if the end of the stream has been reached
Throws:
IOException - if an I/O error occurs.
StreamIntegrityException - if the final byte has been read and the HMAC fails validation

read

public int read(byte[] b)
         throws IOException,
                StreamIntegrityException
The read(b) method for class AES256JNCryptorInputStream has the same effect as:

read(b, 0, b.length)

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.
StreamIntegrityException - if the final byte has been read and the HMAC fails validation

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads a number of bytes into the byte array. If this includes the last byte in the stream (determined by peeking ahead to the next byte), the value of the HMAC is verified. If the verification fails an exception is thrown.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
NullPointerException - If b is null.
IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off
StreamIntegrityException - if the final byte has been read and the HMAC fails validation

close

public void close()
           throws IOException
Closes the underlying input stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException


Copyright © 2014. All Rights Reserved.