|
||||||||||
| 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
|
+--javax.crypto.CipherInputStream
Class for en/decrypting data read from an input stream.
Attention: This is not a SUN implementation!
This class has been developed by IAIK according to the documentation publicly
available.
For SUNīs documentation of this class see
http://java.sun.com/security/JCE1.2/spec/apidoc/index.html
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));
}
InputStream,
FilterInputStream,
Cipher,
CipherOutputStream| Fields inherited from class java.io.FilterInputStream |
in |
| Constructor Summary | |
protected |
CipherInputStream(java.io.InputStream is)
Creates a CipherInputStream only from an InputStream. |
|
CipherInputStream(java.io.InputStream is,
Cipher cipher)
Creates a CipherInputStream using an InputStream and a Cipher initialized for either encryption or decryption. |
|
CipherInputStream(java.io.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(java.io.InputStream is,
Cipher cipher)
is - the input streamcipher - an initialized cipherCipher
public CipherInputStream(java.io.InputStream is,
Cipher cipher,
int bufferSize)
is - the input streamcipher - an initialized cipherbufferSize - size of the internal bufferCipherprotected CipherInputStream(java.io.InputStream is)
is - the input stream| Method Detail |
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
off. The decrypted data is unpadded only if the end (EOF)
of the underlying input stream is reached.b - the byte array into which the data bytes are readoff - the start offset of the datalen - the maximum number of bytes to be read
public int read(byte[] b)
throws java.io.IOException
b - the byte array into which the data bytes are read
public int read()
throws java.io.IOException
public long skip(long n)
throws java.io.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.
n - the number of data bytes to skip
public int available()
throws java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||