Package org.alfresco.encryption
Class EncryptingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.alfresco.encryption.EncryptingOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class EncryptingOutputStream extends java.io.OutputStream
An output stream that encrypts data to another output stream. A lightweight yet secure hybrid encryption scheme is used. A random symmetric key is generated and encrypted using the receiver's public key. The supplied data is then encrypted using the symmetric key and sent to the underlying stream on a streaming basis. An HMAC checksum is also computed on an ongoing basis and appended to the output when the stream is closed. This class can be used in conjunction withDecryptingInputStream
to transport data securely.
-
-
Constructor Summary
Constructors Constructor Description EncryptingOutputStream(java.io.OutputStream wrapped, java.security.PublicKey receiverKey, java.lang.String algorithm, java.security.SecureRandom rand, int strength, java.lang.String mode, java.lang.String padding)
Constructs an EncryptingOutputStream.EncryptingOutputStream(java.io.OutputStream wrapped, java.security.PublicKey receiverKey, java.security.SecureRandom rand)
Constructs an EncryptingOutputStream using default symmetric encryption parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Constructor Detail
-
EncryptingOutputStream
public EncryptingOutputStream(java.io.OutputStream wrapped, java.security.PublicKey receiverKey, java.security.SecureRandom rand) throws java.io.IOException, java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Constructs an EncryptingOutputStream using default symmetric encryption parameters.- Parameters:
wrapped
- outputstream to store the encrypted datareceiverKey
- the receiver's public key for encrypting the symmetric keyrand
- a secure source of randomness- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.java.security.NoSuchAlgorithmException
- the no such algorithm exceptionjavax.crypto.NoSuchPaddingException
- the no such padding exceptionjava.security.InvalidKeyException
- the invalid key exceptionjavax.crypto.BadPaddingException
- the bad padding exceptionjavax.crypto.IllegalBlockSizeException
- the illegal block size exception
-
EncryptingOutputStream
public EncryptingOutputStream(java.io.OutputStream wrapped, java.security.PublicKey receiverKey, java.lang.String algorithm, java.security.SecureRandom rand, int strength, java.lang.String mode, java.lang.String padding) throws java.io.IOException, java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Constructs an EncryptingOutputStream.- Parameters:
wrapped
- outputstream to store the encrypted datareceiverKey
- the receiver's public key for encrypting the symmetric keyalgorithm
- symmetric encryption algorithm (e.g. "AES")rand
- a secure source of randomnessstrength
- the key size in bits (e.g. 128)mode
- encryption mode (e.g. "CBC")padding
- padding scheme (e.g. "PKCS5PADDING")- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.java.security.NoSuchAlgorithmException
- the no such algorithm exceptionjavax.crypto.NoSuchPaddingException
- the no such padding exceptionjava.security.InvalidKeyException
- the invalid key exceptionjavax.crypto.BadPaddingException
- the bad padding exceptionjavax.crypto.IllegalBlockSizeException
- the illegal block size exception
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
-