KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > runtime > CipherOutputStream


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.runtime;
12
13 import java.io.*;
14
15 /**
16  * Encrypts a stream of data that can be decrypted using the
17  * <code>Cipher</code> or <code>CipherInputStream</code>.
18  *
19  * @see Cipher
20  * @see CipherInputStream
21  */

22 public class CipherOutputStream extends FilterOutputStream {
23     private Cipher cipher;
24
25     /**
26      * Constructs a new <code>CipherOutputStream</code> that encrypts the
27      * data in the given <code>OutputStream</code>. Once the data is
28      * encrypted it can be decrypted by suppying the encrupted data and
29      * given password to a <code>Cipher</code> or
30      * <code>CipherInputStream</code>.
31      *
32      * @param os
33      * @param password
34      */

35     public CipherOutputStream(OutputStream os, String JavaDoc password) {
36         super(os);
37         cipher = new Cipher(Cipher.ENCRYPT_MODE, password);
38     }
39
40     /**
41      * @see OutputStream#write(int)
42      */

43     public void write(int b) throws IOException {
44         try {
45             out.write(cipher.cipher((byte) b));
46         } catch (Exception JavaDoc e) {
47             throw new IOException(e.getMessage());
48         }
49     }
50 }
51
Popular Tags