All Packages Class Hierarchy This Package Previous Next Index
Class IS.hi.logir.cryptonite.EncryptStream
java.lang.Object
|
+----java.io.OutputStream
|
+----java.io.FilterOutputStream
|
+----IS.hi.logir.cryptonite.EncryptStream
- public final class EncryptStream
- extends FilterOutputStream
This class is a FilterOutputStream that encrypts everything passing through it.
The format of the encrypted stream is as follows:
encrypted stream = <key identifier>[block [... [block] ...]]
block = <key identifier | session key | encrypted block>
key identifier = <0x00000000><MD5 fingerprint>
session key = <negative length of block><serialized and encrypted Key object>
key-class name length = 32-bit integer
key-class name = string
cipher block = <decrypted size><cipher chunk>[cipher chunk[... [cipher chunk]... ]]
The definition of key depends on the particular key class.
The definition of cipher chunk and a more detailed explanation of
cipher block is shown in the documantation of the class Key.
The last key identifier before a session key block
identifies the key used to encrypt the session key.
The last session key before a cipher block contains the
key used to decrypt that block. If no session key block has
appeared, then the key from the last key identifier block should
be used in stead.
- Author:
- Logi Ragnarsson (logir@hi.is)
- See Also:
- Key, DecryptStream
-
buf
-
-
bufSize
-
-
idealBufSize
-
-
key
-
-
sKey
-
-
EncryptStream(OutputStream, Key)
- Create a new stream which encrypts data written to it and writes it to
out.
-
EncryptStream(OutputStream, Key, int)
- Create a new stream which encrypts data written to it and writes it to
out.
-
close()
- Closes this output stream and releases any system
resources associated with the stream.
-
flush()
- Flushes this output stream and forces any buffered
output bytes to be encrypted and written.
-
init(int, Key)
-
-
resizeBuffer()
-
-
setKey(Key)
- Sets the key to use for encrypting data.
-
setSessionKey(Key)
- Set the session key to use for this stream.
-
write(byte[])
- Encrypts and writes b.length bytes to the stream.
-
write(byte[], int, int)
- Encrypts and writes len bytes from the specified byte array starting at
offset off to this output stream.
-
write(int)
- Encrypt and write the specified byte to the stream.
-
writeBuffer()
-
-
writeKey()
-
key
private Key key
sKey
private Key sKey
buf
private Data buf
bufSize
private int bufSize
idealBufSize
private int idealBufSize
EncryptStream
public EncryptStream(OutputStream out,
Key key,
int idealBufSize) throws IOException
- Create a new stream which encrypts data written to it and writes it to
out. The specified key is used to encrypt the data in blocks of up to
most idealBufSize bytes.
EncryptStream
public EncryptStream(OutputStream out,
Key key) throws IOException
- Create a new stream which encrypts data written to it and writes it to
out. The specified key is used to encrypt the data in blocks of up to
2KB.
init
private void init(int bufSize,
Key key) throws IOException
close
public synchronized void close() throws IOException
- Closes this output stream and releases any system
resources associated with the stream.
- Overrides:
- close in class FilterOutputStream
writeBuffer
private synchronized void writeBuffer() throws IOException
flush
public synchronized void flush() throws IOException
- Flushes this output stream and forces any buffered
output bytes to be encrypted and written.
- Overrides:
- flush in class FilterOutputStream
write
public synchronized void write(byte b[]) throws IOException
- Encrypts and writes b.length bytes to the stream.
- Overrides:
- write in class FilterOutputStream
write
public synchronized void write(byte b[],
int off,
int len) throws IOException
- Encrypts and writes len bytes from the specified byte array starting at
offset off to this output stream.
- Overrides:
- write in class FilterOutputStream
write
public synchronized void write(int b) throws IOException
- Encrypt and write the specified byte to the stream.
- Overrides:
- write in class FilterOutputStream
resizeBuffer
private void resizeBuffer() throws IOException
setKey
public synchronized void setKey(Key key) throws IOException
- Sets the key to use for encrypting data. If a key identifier block has
previously been written, another one will be written to reflect the
change.
writeKey
private synchronized void writeKey() throws IOException
setSessionKey
public synchronized void setSessionKey(Key sk) throws IOException
- Set the session key to use for this stream. Session keys can be
use symmetric ciphers, which tend to be much faster than the
public key ciphers used in the constructor. The session key will
be encrypted with the public key and written to the stream.
All Packages Class Hierarchy This Package Previous Next Index