Package org.alfresco.encryption
Class EncryptingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.alfresco.encryption.EncryptingOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class EncryptingOutputStream extends 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(OutputStream wrapped, PublicKey receiverKey, String algorithm, SecureRandom rand, int strength, String mode, String padding)
Constructs an EncryptingOutputStream.EncryptingOutputStream(OutputStream wrapped, PublicKey receiverKey, 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)
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
EncryptingOutputStream
public EncryptingOutputStream(OutputStream wrapped, PublicKey receiverKey, SecureRandom rand) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, 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:
IOException
- Signals that an I/O exception has occurred.NoSuchAlgorithmException
- the no such algorithm exceptionNoSuchPaddingException
- the no such padding exceptionInvalidKeyException
- the invalid key exceptionBadPaddingException
- the bad padding exceptionIllegalBlockSizeException
- the illegal block size exception
-
EncryptingOutputStream
public EncryptingOutputStream(OutputStream wrapped, PublicKey receiverKey, String algorithm, SecureRandom rand, int strength, String mode, String padding) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, 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:
IOException
- Signals that an I/O exception has occurred.NoSuchAlgorithmException
- the no such algorithm exceptionNoSuchPaddingException
- the no such padding exceptionInvalidKeyException
- the invalid key exceptionBadPaddingException
- the bad padding exceptionIllegalBlockSizeException
- the illegal block size exception
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] b) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
-