Class CryptoInputStream<K extends MasterKey<K>>
- java.lang.Object
-
- java.io.InputStream
-
- com.amazonaws.encryptionsdk.CryptoInputStream<K>
-
- Type Parameters:
K- The type ofMasterKeys used to manipulate the data.
- All Implemented Interfaces:
Closeable,AutoCloseable
public class CryptoInputStream<K extends MasterKey<K>> extends InputStream
A CryptoInputStream is a subclass of java.io.InputStream. It performs cryptographic transformation of the bytes passing through it.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns metadata associated with the performed cryptographic operation.voidclose()CryptoResult<CryptoInputStream<K>,K>getCryptoResult()Returns the result of the cryptographic operations including associate metadata.intread()intread(byte[] b)intread(byte[] b, int off, int len)voidsetMaxInputLength(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, transferTo
-
-
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws IllegalArgumentException, IOException, BadCiphertextException- Overrides:
readin classInputStream- Throws:
BadCiphertextException- This is thrown only during decryption if b contains invalid or corrupt ciphertext.IllegalArgumentExceptionIOException
-
read
public int read(byte[] b) throws IllegalArgumentException, IOException, BadCiphertextException- Overrides:
readin classInputStream- Throws:
BadCiphertextException- This is thrown only during decryption if b contains invalid or corrupt ciphertext.IllegalArgumentExceptionIOException
-
read
public int read() throws IOException, BadCiphertextException- Specified by:
readin classInputStream- Throws:
BadCiphertextException- if b contains invalid or corrupt ciphertext. This is thrown only during decryption.IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
public int available() throws IOExceptionReturns metadata associated with the performed cryptographic operation.- Overrides:
availablein 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 theCachingCryptoMaterialsManager. If the input size set here is exceeded, an exception will be thrown, and the encyption or decryption will fail.- Parameters:
size- Maximum input size.
-
getCryptoResult
public CryptoResult<CryptoInputStream<K>,K> getCryptoResult() throws BadCiphertextException, IOException
Returns the result of the cryptographic operations including associate metadata.- Throws:
IOExceptionBadCiphertextException
-
-