K
- The type of MasterKey
s used to manipulate the data.public class CryptoInputStream<K extends MasterKey<K>> extends InputStream
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
.
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns metadata associated with the performed cryptographic operation.
|
void |
close() |
CryptoResult<CryptoInputStream<K>,K> |
getCryptoResult()
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.
|
mark, markSupported, reset, skip
public int read(byte[] b, int off, int len) throws IllegalArgumentException, IOException, BadCiphertextException
read
in class InputStream
BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.IllegalArgumentException
IOException
public int read(byte[] b) throws IllegalArgumentException, IOException, BadCiphertextException
read
in class InputStream
BadCiphertextException
- This is thrown only during decryption if b contains invalid or
corrupt ciphertext.IllegalArgumentException
IOException
public int read() throws IOException, BadCiphertextException
read
in class InputStream
BadCiphertextException
- if b contains invalid or corrupt ciphertext. This is thrown only
during decryption.IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void setMaxInputLength(long size)
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.
size
- Maximum input size.public CryptoResult<CryptoInputStream<K>,K> getCryptoResult() throws BadCiphertextException, IOException
IOException
BadCiphertextException
Copyright © 2023. All rights reserved.