h36532 s 00003/00003/00231 d D 1.4 97/12/09 15:24:43 luehe 5 4 c rm ,* e s 00000/00022/00234 d D 1.3 97/10/22 15:25:07 luehe 4 3 c removed examples e s 00032/00011/00224 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:14 Codemgr 2 1 c SunPro Code Manager data about conflicts, renames, etc... c Name history : 1 0 security/JCE1.2/earlyaccess/javax.crypto.CipherOutputStream.html e s 00235/00000/00000 d D 1.1 97/10/09 09:58:13 luehe 1 0 c date and time created 97/10/09 09:58:13 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.CipherOutputStream
D 3
All Packages  Class Hierarchy  This Package  Previous  Next  Index
E 3 I 3 D 5 All Packages Class Hierarchy This Package Previous Next Index E 5 I 5 All Packages Class Hierarchy This Package Previous Next Index E 5 E 3

Class javax.crypto.CipherOutputStream

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----javax.crypto.CipherOutputStream

public class CipherOutputStream
extends FilterOutputStream
A CipherOutputStream is composed of an OutputStream and a Cipher so that write() methods first process the data before writing them out to the underlying OutputStream. The Cipher must be fully D 3 initialized before being used by a SecureOutputStream.

For example, if the Cipher is initialized for decryption, the SecureOutputStream will attempt to encrypt data before writing out the encrypted data. E 3 I 3 initialized before being used by a CipherOutputStream.

For example, if the Cipher is initialized for encryption, the CipherOutputStream will attempt to encrypt data before writing out the encrypted data. E 3

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.OutputStream and java.io.FilterOutputStream. 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. 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 CipherOutputStream. D 3

code example ... E 3 I 3 D 4

The following example demonstrates the usage of CipherOutputStream, where several instances of CipherOutputStream and OutputStream are connected. It is assumed that cipher1 and cipher2 have been initialized for decryption and encryption (with corresponding keys), respectively.

 FileInputStream fis = new FileInputStream("/tmp/a.txt");
 FileOutputStream fos = new FileOutputStream("/tmp/b.txt");
 CipherOutputStream cos1 = new CipherOutputStream(fos, cipher1);
 CipherOutputStream cos2 = new CipherOutputStream(cos1, cipher2);
 byte[] b = new byte[8];
 int i = fis.read(b);
 while (i != -1) {
     cos2.write(b, 0, i);
     i = fis.read(b);
 }
 cos2.flush();
 
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 before it is written to /tmp/b.txt. E 4 E 3

Since:
JCE1.2
See Also:
OutputStream, FilterOutputStream, Cipher, CipherInputStream

Constructor Index

 o CipherOutputStream(OutputStream)
Constructs a CipherOutputStream from an OutputStream without specifying a Cipher.
 o CipherOutputStream(OutputStream, Cipher)
Constructs a CipherOutputStream from an OutputStream and a Cipher.

Method Index

 o close()
Closes this output stream and releases any system resources associated with this stream.
 o flush()
Flushes this output stream and forces any buffered output bytes to be written out.
 o write(byte[])
Writes b.length bytes from the specified byte array to this output stream.
 o write(byte[], int, int)
Writes len bytes from the specified byte array starting at offset off to this output stream.
 o write(int)
Writes the specified byte to this output stream.

Constructors

 o CipherOutputStream
 public CipherOutputStream(OutputStream os,
                           Cipher c)
Constructs a CipherOutputStream from an OutputStream and a Cipher.

 o CipherOutputStream
 protected CipherOutputStream(OutputStream os)
Constructs a CipherOutputStream from an OutputStream without specifying a Cipher. This has the effect of constructing a CipherOutputStream using a NullCipher.

Methods

 o write
 public void write(int b) throws IOException
Writes the specified byte to this output stream.

Parameters:
b - the byte.
Throws: IOException
if an I/O error occurs.
Overrides:
write in class FilterOutputStream
 o write
 public void write(byte b[]) throws IOException
Writes b.length bytes from the specified byte array to this output stream.

The write method of CipherOutputStream calls the write method of three arguments with the three arguments b, 0, and b.length.

Parameters:
b - the data.
Throws: IOException
if an I/O error occurs.
Overrides:
write in class FilterOutputStream
See Also:
write
 o write
 public void write(byte b[],
                   int off,
                   int len) throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws: IOException
if an I/O error occurs.
Overrides:
write in class FilterOutputStream
 o flush
 public void flush() throws IOException
Flushes this output stream and forces any buffered output bytes to be written out.

Throws: IOException
if an I/O error occurs.
Overrides:
flush in class FilterOutputStream
 o close
 public void close() throws IOException
Closes this output stream and releases any system resources associated with this stream.

The close method of CipherOutputStream calls its flush method, and then calls the close method of its underlying output stream.

Throws: IOException
if an I/O error occurs.
Overrides:
close in class FilterOutputStream

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