h48108 s 00006/00076/00304 d D 1.4 97/12/09 15:24:42 luehe 5 4 c rm ,* e s 00000/00019/00380 d D 1.3 97/10/22 15:25:05 luehe 4 3 c removed examples e s 00020/00021/00379 d D 1.2 97/10/18 13:59:53 luehe 3 1 c removed examples e s 00000/00000/00000 d R 1.2 97/10/09 09:58:13 Codemgr 2 1 c SunPro Code Manager data about conflicts, renames, etc... c Name history : 1 0 security/JCE1.2/earlyaccess/javax.crypto.CipherInputStream.html e s 00400/00000/00000 d D 1.1 97/10/09 09:58:12 luehe 1 0 c date and time created 97/10/09 09:58:12 by luehe e u U f e 0 t T I 1 D 3 E 3 I 3 D 5 E 5 I 5 E 5 E 3 Class javax.crypto.CipherInputStream
D 3
All Packages  Class Hierarchy  This Package  Previous  Next  Index
E 3 I 3 All Packages Class Hierarchy This Package Previous Next Index E 3

Class javax.crypto.CipherInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----javax.crypto.CipherInputStream

public class CipherInputStream
extends FilterInputStream
A CipherInputStream is composed of an InputStream and a Cipher so that read() methods return data that are read in from the underlying InputStream but have been additionally processed by the Cipher. The Cipher must be fully initialized before being used by D 3 a SecureInputStream. E 3 I 3 a CipherInputStream. E 3

For example, if the Cipher is initialized for decryption, the D 3 SecureInputStream will attempt to read in data and decrypt them, E 3 I 3 CipherInputStream will attempt to read in data and decrypt them, E 3 before returning the decrypted data.

This class adheres strictly to the semantics, especially the D 3 failure semantics, given for its ancestor classes E 3 I 3 failure semantics, of its ancestor classes E 3 java.io.FilterInputStream and java.io.InputStream. This class has exactly those methods specified in its ancestor classes, and D 3 override them all. Moreover, this class catches all exceptions E 3 I 3 overrides them all. Moreover, this class catches all exceptions E 3 that are not thrown by its ancestor classes. In particular, the D 3 skip(long) method skips only data that have been E 3 I 3 skip(long) method skips only data that have been E 3 processed by the Cipher. D 3

It is crucial for a programmer using this class to not to use E 3 I 3

It is crucial for a programmer using this class not to use E 3 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. D 3

As an example of its usage, suppose cipher1 and cipher2 have been initialized for encryption and decryption (with corresponding crypto keys) respectively, the code below demonstrates how to easily connect several instances of SecureInputStream and InputStream. E 3 I 3 D 4

As an example of its usage, suppose cipher1 and cipher2 have been initialized for encryption and decryption (with corresponding keys), respectively. The code below demonstrates how to easily connect several instances of CipherInputStream and InputStream: E 3

 FileInputStream fis = new FileInputStream("/tmp/a.txt");
D 3
 SecureInputStream sis1 = new SecureInputStream(fis, cipher1);
 SecureInputStream sis2 = new SecureInputStream(sis1, cipher2);
E 3
I 3
 CipherInputStream cis1 = new CipherInputStream(fis, cipher1);
 CipherInputStream cis2 = new CipherInputStream(cis1, cipher2);
E 3
 FileOutputStream fos = new FileOutputStream("/tmp/b.txt");
 byte[] b = new byte[8];
D 3
 int i = sis2.read(b);
E 3
I 3
 int i = cis2.read(b);
E 3
 while (i != -1) {
     fos.write(b, 0, i);
D 3
     i = sis2.read(b);
E 3
I 3
     i = cis2.read(b);
E 3
 }
 
D 3 The above program copies the content from file /tmp/a.txt to /tmp/b.txt, except that in the process the content has been first encrypted and then decrypted back. E 3 I 3 The above program copies the content from file /tmp/a.txt to /tmp/b.txt, except that the content is first encrypted and then decrypted back when it is read from /tmp/a.txt. E 4 E 3

Since:
JCE1.2
See Also:
InputStream, FilterInputStream, Cipher, CipherOutputStream

Constructor Index

 o CipherInputStream(InputStream)
Constructs a CipherInputStream from an InputStream without specifying a Cipher.
 o CipherInputStream(InputStream, Cipher)
Constructs a CipherInputStream from an InputStream and a Cipher.

Method Index

 o available()
Returns the number of bytes that can be read from this input stream without blocking.
 o close()
Closes this input stream and releases any system resources associated with the stream.
 o D 5 mark(int)
Marks the current position in this input stream.
 o E 5 markSupported()
Tests if this input stream supports the mark D 5 and reset methods. E 5 I 5 and reset methods, which it does not. E 5
 o read()
Reads the next byte of data from this input stream.
 o read(byte[])
Reads up to b.length bytes of data from this input stream into an array of bytes.
 o read(byte[], int, int)
Reads up to len bytes of data from this input stream into an array of bytes.
 o D 5 reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.
 o E 5 skip(long)
Skips over and discards n bytes of data from this input stream.

Constructors

 o CipherInputStream
 public CipherInputStream(InputStream is,
                          Cipher c)
Constructs a CipherInputStream from an InputStream and a Cipher.

 o CipherInputStream
 protected CipherInputStream(InputStream is)
Constructs a CipherInputStream from an InputStream without specifying a Cipher. This has the effect of constructing a CipherInputStream using a NullCipher.

Methods

 o read
 public int read() throws IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class FilterInputStream
 o read
 public int read(byte b[]) throws IOException
Reads up to b.length bytes of data from this input stream into an array of bytes.

The read method of InputStream calls the read method of three arguments with the arguments b, 0, and b.length.

Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class FilterInputStream
See Also:
read
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available. If the first argument is null, up to len bytes are read and discarded.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes 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.
Overrides:
read in class FilterInputStream
See Also:
read
 o skip
 public long skip(long n) throws IOException
Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws: IOException
if an I/O error occurs.
Overrides:
skip in class FilterInputStream
 o available
 public int available() throws IOException
Returns the number of bytes that can be read from this input stream without blocking. The available method of InputStream returns 0. This method should be overridden by subclasses.

Returns:
the number of bytes that can be read from this input stream without blocking.
Throws: IOException
if an I/O error occurs.
Overrides:
available in class FilterInputStream
 o close
 public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream.

The close method of CipherInputStream calls the close method of its underlying input stream.

Throws: IOException
if an I/O error occurs.
Overrides:
close in class FilterInputStream
D 5  o mark
 public synchronized void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The mark method of FilterInputStream calls the mark method of its underlying input stream with the readlimit argument.

Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
Overrides:
mark in class FilterInputStream
See Also:
reset
 o reset
 public synchronized void reset() throws IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

The reset method of FilterInputStream calls the reset method of its underlying input stream.

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parser, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails, which, if it happens within readlimit bytes, allows the outer code to reset the stream and try another parser.

Throws: IOException
if this stream has not been marked or if the mark has been invalidated.
Overrides:
reset in class FilterInputStream
See Also:
mark, IOException
E 5  o markSupported
 public boolean markSupported()
Tests if this input stream supports the mark D 5 and reset methods. The markSupported method of CipherInputStream calls the markSupported method of its underlying input stream and returns whatever value that method returns. E 5 I 5 and reset methods, which it does not. E 5

Returns: D 5
true if this true type supports the mark and reset method; false otherwise. E 5 I 5
false, since this class does not support the mark and reset methods. E 5
Overrides:
markSupported in class FilterInputStream
See Also: D 5
mark, reset E 5 I 5
mark, reset E 5

D 3
All Packages  Class Hierarchy  This Package  Previous  Next  Index
E 3 I 3 All Packages Class Hierarchy This Package Previous Next Index E 3 E 1