Table of Contents

Class AesGcmEncryptStream

Namespace
Amazon.Extensions.S3.Encryption.Util
Assembly
Amazon.Extensions.S3.Encryption.dll

A wrapper stream that encrypts the base stream using AES GCM algorithm as it is being read.

public class AesGcmEncryptStream : EncryptStream, IDisposable
Inheritance
AesGcmEncryptStream
Implements
Derived

Constructors

AesGcmEncryptStream(Stream, byte[], byte[], int, byte[])

Constructor for initializing encryption stream

public AesGcmEncryptStream(Stream baseStream, byte[] key, byte[] nonce, int tagSizeInBit, byte[] associatedText = null)

Parameters

baseStream Stream

Original data stream

key byte[]

Key to be used for encryption

nonce byte[]

Nonce to be used for encryption

tagSizeInBit int

Tag size for the tag appended in the end of the stream

associatedText byte[]

Additional associated data

Properties

Length

Gets the length in bytes of the stream. Length of the string is sum of nonce, cipher text and tag

public override long Length { get; }

Property Value

long

Position

Gets or sets the position within the current stream.

public override long Position { get; set; }

Property Value

long

Methods

Close()

Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.

public override void Close()

Read(byte[], int, int)

Reads a sequence of encrypted bytes from the current stream and advances the position within the stream by the number of bytes read.

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

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.

offset int

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

count int

The 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 a sequence of encrypted bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

Parameters

buffer byte[]

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.

offset int

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

count int

The maximum number of bytes to be read from the current stream.

cancellationToken CancellationToken

The 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