Class CryptoInputStream<K extends MasterKey<K>>
- Type Parameters:
K
- The type ofMasterKey
s used to manipulate the data.
- All Implemented Interfaces:
Closeable
,AutoCloseable
The CryptoInputStream wraps a provided InputStream object and performs cryptographic transformation of the bytes read from the wrapped InputStream. It uses the cryptography handler provided during construction to invoke methods that perform the cryptographic transformations.
In short, reading from the CryptoInputStream returns bytes that are the cryptographic transformations of the bytes read from the wrapped InputStream.
For example, if the cryptography handler provides methods for decryption, the CryptoInputStream will read ciphertext bytes from the wrapped InputStream, decrypt, and return them as plaintext bytes.
This class adheres strictly to the semantics, especially the failure semantics, of its ancestor class java.io.InputStream. This class overrides all the methods specified in its ancestor class.
To instantiate an instance of this class, please see AwsCrypto
.
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns metadata associated with the performed cryptographic operation.void
close()
Returns the result of the cryptographic operations including associate metadata.int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
setMaxInputLength(long size)
Sets an upper bound on the size of the input data.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Method Details
-
read
public int read(byte[] b, int off, int len) throws IllegalArgumentException, IOException, BadCiphertextException- Overrides:
read
in classInputStream
- Throws:
BadCiphertextException
- This is thrown only during decryption if b contains invalid or corrupt ciphertext.IllegalArgumentException
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
BadCiphertextException
- This is thrown only during decryption if b contains invalid or corrupt ciphertext.IllegalArgumentException
IOException
-
read
- Specified by:
read
in classInputStream
- Throws:
BadCiphertextException
- if b contains invalid or corrupt ciphertext. This is thrown only during decryption.IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
available
Returns metadata associated with the performed cryptographic operation.- Overrides:
available
in classInputStream
- Throws:
IOException
-
setMaxInputLength
public void setMaxInputLength(long size)Sets an upper bound on the size of the input data. This method should be called before reading any data from the stream. If this method is not called prior to reading any data, performance may be reduced (notably, it will not be possible to cache data keys when encrypting).Among other things, this size is used to enforce limits configured on the
CachingCryptoMaterialsManager
.If the input size set here is exceeded, an exception will be thrown, and the encyption or decryption will fail.
If this method is called multiple times, the smallest bound will be used.
- Parameters:
size
- Maximum input size.
-
getCryptoResult
public CryptoResult<CryptoInputStream<K>,K> getCryptoResult() throws BadCiphertextException, IOExceptionReturns the result of the cryptographic operations including associate metadata.- Throws:
IOException
BadCiphertextException
-