Class AesGcmEncryptCachingStream
- Namespace
- Amazon.Extensions.S3.Encryption.Util
- Assembly
- Amazon.Extensions.S3.Encryption.dll
A wrapper stream that encrypts the base stream using AES GCM algorithm and caches the contents as it is being read.
public class AesGcmEncryptCachingStream : AesGcmEncryptStream, IDisposable
- Inheritance
-
AesGcmEncryptCachingStream
- Implements
Constructors
AesGcmEncryptCachingStream(Stream, byte[], byte[], int, byte[])
Constructor for initializing encryption stream
public AesGcmEncryptCachingStream(Stream baseStream, byte[] key, byte[] nonce, int tagSizeInBit, byte[] associatedText = null)
Parameters
baseStreamStreamOriginal data stream
keybyte[]Key to be used for encryption
noncebyte[]Nonce to be used for encryption
tagSizeInBitintTag size for the tag appended in the end of the stream
associatedTextbyte[]Additional associated data
Properties
CanSeek
Gets a value indicating whether the current stream supports seeking.
public override bool CanSeek { get; }
Property Value
Position
Gets or sets the position within the current stream.
public override long Position { get; set; }
Property Value
Methods
ClearReadBufferToPosition()
Clear read bytes buffer before current position
public void ClearReadBufferToPosition()
Read(byte[], int, int)
Reads and cache a sequence of encrypted bytes in _readBuffer from the current stream and advances the position within the stream by the number of bytes read. If current position lies in between lower bound and upper bound of _readBuffer, reads from the _readBuffer, else read from the original stream
public override int Read(byte[] buffer, int offset, int count)
Parameters
bufferbyte[]An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offsetintThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countintThe maximum number of bytes to be read from the current stream.
Returns
- int
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
Exceptions
- AmazonCryptoException
Underlying crypto exception wrapped in Amazon exception
ReadAsync(byte[], int, int, CancellationToken)
Asynchronously reads and cache a sequence of encrypted bytes in _readBuffer from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests. If current position lies in between lower bound and upper bound of _readBuffer, reads from the _readBuffer, else read from the original stream
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
bufferbyte[]An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offsetintThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countintThe maximum number of bytes to be read from the current stream.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.
Returns
- Task<int>
A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
Exceptions
- AmazonCryptoException
Underlying crypto exception wrapped in Amazon exception