Package org.alfresco.encryption
Class EncryptingOutputStream
java.lang.Object
java.io.OutputStream
org.alfresco.encryption.EncryptingOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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 with
DecryptingInputStream
to transport data securely.-
Constructor Summary
ConstructorsConstructorDescriptionEncryptingOutputStream
(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
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
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 Details
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-