|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.InputStream | +--java.io.FilterInputStream | +--iaik.utils.CipherInputStream
Class for en/decrypting data read from an input stream.
This class provides the same functionality as javax.crypto.CipherInputStream
but allows to specify a buffer size for supporting block oriented encoding
as required by PKCS#7.
This class extends the java.io.FilterInputStream
class for combining
the functionality of an InputStream and a Cipher.
According to the operation mode the Cipher has been initialized with, data that is
read from the underlying input stream will be returned en/decrypted when calling one
of the read()
methods.
You may use a CipherInputStream for reading encrypted data from a file thereby decrypting it for obtaining the plain text, e.g.:
KeyGenerator key_gen = KeyGenerator.getInstance("DES"); Key des_key = key_gen.generateKey(); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, des_key); is = new FileInputStream("encrypted_data.enc"); CipherInputStream cis = new CipherInputStream(is, cipher); byte[] buffer = new byte[100]; int r; while ((r = cis.read(buffer)) != -1) { System.out.print(new String(buffer)); }
Fields inherited from class java.io.FilterInputStream |
in |
Constructor Summary | |
protected |
CipherInputStream(InputStream is)
Creates a CipherInputStream only from an InputStream. |
|
CipherInputStream(InputStream is,
Cipher cipher)
Creates a CipherInputStream using an InputStream and a Cipher initialized for either encryption or decryption. |
|
CipherInputStream(InputStream is,
Cipher cipher,
int bufferSize)
Creates a CipherInputStream using an InputStream, a Cipher initialized for either encryption or decryption and a buffer size. |
Method Summary | |
int |
available()
Returns the number of bytes available without blocking. |
int |
read()
Reads the next data byte read from this input stream and returns it as an int value between 0 and 255, or -1 if the the end of the stream already has been reached. |
int |
read(byte[] b)
Reads a number of data bytes from this input stream into a byte array. |
int |
read(byte[] b,
int off,
int len)
Reads a specified number of data bytes from this input stream into a byte array. |
long |
skip(long n)
Skips over a specified number of data bytes of this input stream and returns the number of bytes skipped. |
Methods inherited from class java.io.FilterInputStream |
close, mark, markSupported, reset |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CipherInputStream(InputStream is, Cipher cipher)
is
- the input streamcipher
- an initialized cipherpublic CipherInputStream(InputStream is, Cipher cipher, int bufferSize)
is
- the input streamcipher
- an initialized cipherbufferSize
- size of the internal bufferprotected CipherInputStream(InputStream is)
is
- the input streamMethod Detail |
public int read(byte[] b, int off, int len) throws IOException
off
. The decrypted data is unpadded only if the end (EOF)
of the underlying input stream is reached.read
in class FilterInputStream
b
- the byte array into which the data bytes are readoff
- the start offset of the datalen
- the maximum number of bytes to be readIOException
- if an I/O error occurspublic int read(byte[] b) throws IOException
read
in class FilterInputStream
b
- the byte array into which the data bytes are readIOException
- if an I/O error occurspublic int read() throws IOException
read
in class FilterInputStream
IOException
- if an I/O error occurspublic long skip(long n) throws IOException
Since the number of bytes actually skipped may not equal (i.e. shorter) the given number of bytes to skip, the number of bytes actually skipped are returned.
skip
in class FilterInputStream
n
- the number of data bytes to skipIOException
- if an I/O error occurspublic int available() throws IOException
available
in class FilterInputStream
IOException
- if an I/O error occurs
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |