|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /usr/share/javadoc/cryptix-3.2.0/xjava/security/ |
Upload File : |
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE html PUBLIC "-//gnu.org///DTD XHTML 1.1 plus Target 1.0//EN" "../../resources/xhtml11-target10.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>CipherOutputStream (cryptix JavaDoc)</title><script src="../../resources/gjdoc.js" type="text/javascript"><!-- this comment required for konqueror 3.2.2 --></script><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"/><meta name="generator" content="GNU Gjdoc Standard Doclet"/><meta name="keywords" content="xjava.security.CipherOutputStream class"/><meta name="keywords" content="write()"/><meta name="keywords" content="flush()"/><meta name="keywords" content="close()"/><link rel="stylesheet" type="text/css" href="../../resources/gjdochtml-clean-layout.css" title="GNU Clean"/><link rel="stylesheet" type="text/css" href="../../resources/gjdochtml-clean-color1.css" title="GNU Clean"/></head><body class="content class" onload="if(parent.contentPageLoaded)parent.contentPageLoaded(document.title)"><table class="navbar div top"><tr><td class="navbar div top"><div class="navbar div top"><span class="navbar item enabled"><a href="../../overview-summary.html">Overview</a></span> <span class="navbar item enabled"><a href="package-summary.html">Package</a></span> <span class="navbar item enabled"><a href="tree.html">Tree</a></span> <span class="navbar item enabled"><a href="../../alphaindex.html">Index</a></span> <span class="navbar item enabled"><a href="../../deprecated.html">Deprecated</a></span> <span class="navbar item enabled"><a href="../../about.html">About</a></span></div></td></tr><tr><td class="navi"><a href="../../xjava/security/CipherInputStream.html">Prev Class</a> | <a href="../../xjava/security/ExtendedKeyGenerator.html">Next Class</a></td><td class="navi"><a href="../../index.html" title="Show in a frameset" target="_top">Frames</a> | <a href="CipherOutputStream.html" title="Show without frames" target="_top">No Frames</a> </td></tr><tr><td class="navi">Summary: Nested | Field | <a href="#summary-methods">Method</a> | <a href="#summary-constructors">Constr</a></td><td class="navi">Detail: Nested | Field | <a href="#detail-methods">Method</a> | <a href="#detail-constructors">Constr</a></td></tr></table><div class="class title outer"><h3 class="class title-package">xjava.security</h3><h1 class="class title-class">Class CipherOutputStream</h1></div><div class="class inheritance-tree"><ul class="inheritance 0"><li class="inheritance 0"><code>FilterOutputStream</code></li><li><ul class="inheritance 1"><li class="inheritance 1"><code>xjava.security.CipherOutputStream</code></li><li></li></ul></li></ul></div><hr/><div class="class synopsis outer"><div class="class synopsis declaration"><code>public class <b class="class synopsis name">CipherOutputStream</b></code></div><div class="class synopsis superclass"><code>extends FilterOutputStream</code></div></div><hr/><div class="class description"> A FilterOutputStream that encrypts or decrypts the data passing
through it.
<p/>
This class has a constructor that takes a Cipher and an output
stream as arguments. The cipher is used to encrypt or decrypt all
data supplied via calls to one of the <code>write</code> methods.
The encryption/decryption result is written to the output stream.
<p/>
For block ciphers, a buffer is used for receiving the data to be
encrypted or decrypted. The maximum number of bytes that may be
buffered at any given time is given by the
<code><a href="#getBufferSize">getBufferSize</a></code> method.
For byte-oriented stream ciphers, no buffering is done (and
<code>getBufferSize()</code> returns 0).
<p/>
To supply the bytes that need to be encrypted/decrypted, make one
or more calls to one of the <code>write</code> methods. After you
have supplied all the data, call <code>close()</code> to ensure
final processing is done.
<p/>
Note: JavaSoft's JCE required calling <code>flush</code> for final
processing, rather than <code>close</code>. However, if you call
<code>flush</code> and then write more data, there will not be
sufficient information available when reading in the stream (e.g.
using <samp>CipherInputStream</samp>), to determine when the flush
happened. Unpadding can only work correctly if no further data is
written after the final processing, which means that <code>close</code>
is the right method to trigger this processing. I'm not sure whether
JavaSoft's implementation works if only <code>close</code> is called,
but calling <code>flush</code> followed by <code>close</code> should
work in both implementations.
<p/>
With a cipher in the ENCRYPT state, the number of bytes not yet
encrypted and written to the stream is kept between 0 and
<code>cipher.getPlaintextBlockSize()-1</code> inclusive. When
<code>close</code> is called, the final data is padded, encrypted, and
the result written to the output stream. If the cipher's padding scheme
is NONE and the final data does not comprise a complete plaintext
block, an <samp>IllegalBlockSizeException</samp> is thrown.
<p/>
With a cipher in the DECRYPT state, [DOCUMENT ME]. When <code>close</code>
is called, an exact number of ciphertext blocks should be in
the buffer (otherwise an <samp>IllegalBlockSizeException</samp> is
thrown). Those blocks are decrypted, unpadded, and written to the
output stream.
<p/>
Note: calling methods of a cipher while it is being used by a
CipherInputStream (apart from methods that have no side-effects,
like <code>getAlgorithm()</code>, <code>get*BlockSize()</code>, etc.)
will probably result in incorrect or unexpected output.
<p/>
<b>Copyright</b> © 1997
<a href="http://www.systemics.com/">Systemics Ltd</a> on behalf of the
<a href="http://www.systemics.com/docs/cryptix/">Cryptix Development Team</a>.
<br/>All rights reserved.
<p/>
<b>$Revision: 1.6 $</b>
</div><div class="taglet"></div><div class="taglet"></div><div class="taglet"><dl class="tag list"><dt class="tag section header"><b>See Also:</b></dt><dd><code>java.security.Cipher</code>, <code>java.security.Cipher.getInputBlockSize</code>, <code>java.security.Cipher.getOutputBlockSize</code>, <code>java.security.CipherInputStream</code></dd></dl></div><div class="taglet"></div><div class="taglet"></div><a name="summary-constructors" id="summary-constructors"/><dl class="table container"><dd><table class="class summary" border="1" width="100%"><tr class="table header"><td colspan="2"><h2 class="table header">Constructor Summary</h2></td></tr><tr><td class="right"><dl class="list"><dt class="synopsis"><code><a href="#CipherOutputStream(OutputStream,xjava.security.Cipher)">CipherOutputStream</a>(OutputStream os, <a href="../../xjava/security/Cipher.html" title="Class in xjava.security">Cipher</a> cipher)</code></dt><dd class="description"> Constructs an output stream using a cipher that must be
initialized for either encryption or decryption, that is, a
cipher whose state is either <code>ENCRYPT</code> or
<code>DECRYPT</code>.</dd></dl></td></tr></table></dd></dl><a name="summary-methods" id="summary-methods"/><dl class="table container"><dd><table class="class summary" border="1" width="100%"><tr class="table header"><td colspan="2"><h2 class="table header">Method Summary</h2></td></tr><tr><td class="left" valign="top"><code class="synopsis"> void</code></td><td class="right"><dl class="list"><dt class="synopsis"><code><a href="#close()">close</a>()</code></dt><dd class="description"> Closes the output stream.</dd></dl></td></tr><tr><td class="left" valign="top"><code class="synopsis"> void</code></td><td class="right"><dl class="list"><dt class="synopsis"><code><a href="#flush()">flush</a>()</code></dt><dd class="description"> Flushes the underlying output stream.</dd></dl></td></tr><tr><td class="left" valign="top"><code class="synopsis"> void</code></td><td class="right"><dl class="list"><dt class="synopsis"><code><a href="#write(byte[],int,int)">write</a>(byte[] in, int offset, int length)</code></dt><dd class="description"> Supplies bytes to be used for encryption or decryption,
depending on the cipher state.</dd></dl></td></tr><tr><td class="left" valign="top"><code class="synopsis"> void</code></td><td class="right"><dl class="list"><dt class="synopsis"><code><a href="#write(int)">write</a>(int b)</code></dt><dd class="description"> Supplies a byte to be used for encryption or decryption,
depending on the cipher state.</dd></dl></td></tr></table></dd></dl><a name="detail-constructors" id="detail-constructors"/><h2 class="section header">Constructor Details</h2><div class="section"><a name="CipherOutputStream(OutputStream,xjava.security.Cipher)" id="CipherOutputStream(OutputStream,xjava.security.Cipher)"/><div class="member detail outer"><h3 class="member detail name">CipherOutputStream</h3><pre class="member detail synopsis">public CipherOutputStream(OutputStream os,
<a href="../../xjava/security/Cipher.html" title="Class in xjava.security">Cipher</a> cipher)</pre><blockquote class="member detail name"><div class="member detail description"> Constructs an output stream using a cipher that must be
initialized for either encryption or decryption, that is, a
cipher whose state is either <code>ENCRYPT</code> or
<code>DECRYPT</code>.
</div><div class="parameter"><dl><dt class="header"><b>Parameters:</b></dt><dd class="item"><code class="name">os</code><span class="separator"> - </span><span class="description">the output stream.</span></dd><dd class="item"><code class="name">cipher</code><span class="separator"> - </span><span class="description">an initialized cipher.</span></dd></dl></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div></blockquote></div></div><a name="detail-methods" id="detail-methods"/><h2 class="section header">Method Details</h2><div class="section"><a name="close()" id="close()"/><div class="member detail outer"><h3 class="member detail name">close</h3><pre class="member detail synopsis">public void close()
throws IOException</pre><blockquote class="member detail name"><div class="member detail description"> Closes the output stream. Before it is closed, buffered data
is processed, taking into account padding, and the result is
written to the stream.
<p/>
For an encrypter stream, any buffered data is encrypted and the
result written to the output stream. If the padding scheme is
not "NONE", the data is padded before encryption. If the padding
scheme is "NONE" and the final data does not comprise a complete
block, an <samp>IllegalBlockSize</samp> exception is thrown.
<p/>
For a decrypter stream, when <code>close</code> is called,
exactly one block should be in the buffer. It is decrypted, unpadded,
and written out.
</div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div></blockquote></div><hr/><a name="flush()" id="flush()"/><div class="member detail outer"><h3 class="member detail name">flush</h3><pre class="member detail synopsis">public void flush()
throws IOException</pre><blockquote class="member detail name"><div class="member detail description"> Flushes the underlying output stream. Unlike JavaSoft's
implementation, this never writes any further data to the stream.
To make sure that all data has been written, call <code>close()</code>.
</div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div></blockquote></div><hr/><a name="write(byte[],int,int)" id="write(byte[],int,int)"/><div class="member detail outer"><h3 class="member detail name">write</h3><pre class="member detail synopsis">public void write(byte[] in,
int offset,
int length)
throws IOException</pre><blockquote class="member detail name"><div class="member detail description"> Supplies bytes to be used for encryption or decryption,
depending on the cipher state.
</div><div class="parameter"><dl><dt class="header"><b>Parameters:</b></dt><dd class="item"><code class="name">in</code><span class="separator"> - </span><span class="description">the buffer containing the bytes to be used for
encryption or decryption.</span></dd><dd class="item"><code class="name">offset</code><span class="separator"> - </span><span class="description">the offset into <i>in</i> indicating the location
of the first byte to be used.</span></dd><dd class="item"><code class="name">length</code><span class="separator"> - </span><span class="description">the number of bytes to read from <i>in</i>,
starting at offset <i>offset</i>.</span></dd></dl></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div></blockquote></div><hr/><a name="write(int)" id="write(int)"/><div class="member detail outer"><h3 class="member detail name">write</h3><pre class="member detail synopsis">public void write(int b)
throws IOException</pre><blockquote class="member detail name"><div class="member detail description"> Supplies a byte to be used for encryption or decryption,
depending on the cipher state.
</div><div class="parameter"><dl><dt class="header"><b>Parameters:</b></dt><dd class="item"><code class="name">b</code><span class="separator"> - </span><span class="description">the byte to be used for encryption or decryption.</span></dd></dl></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div><div class="taglet"></div></blockquote></div></div><p class="navbar bottom spacer"> </p><table class="navbar div bottom"><tr><td><div class="navbar div top"><span class="navbar item enabled"><a href="../../overview-summary.html">Overview</a></span> <span class="navbar item enabled"><a href="package-summary.html">Package</a></span> <span class="navbar item enabled"><a href="tree.html">Tree</a></span> <span class="navbar item enabled"><a href="../../alphaindex.html">Index</a></span> <span class="navbar item enabled"><a href="../../deprecated.html">Deprecated</a></span> <span class="navbar item enabled"><a href="../../about.html">About</a></span></div></td></tr></table></body></html>