Class MD5Stream
A wrapper stream that calculates an MD5 hash of the base stream as it is being read or written. The calculated hash is only available after the stream is closed or CalculateHash is called. After calling CalculateHash, any further reads on the streams will not change the CalculatedHash. If an ExpectedHash is specified and is not equal to the calculated hash, Close or CalculateHash methods will throw an AmazonClientException. If base stream's position is not 0 or HashOnReads is true and the entire stream is not read, the CalculatedHash will be set to an empty byte array and comparison to ExpectedHash will not be made.
public class MD5Stream : HashStream<HashingWrapperMD5>, IDisposable, IAsyncDisposable
- Inheritance
-
MD5Stream
- Implements
- Inherited Members
Constructors
MD5Stream(Stream, byte[], long)
Initializes an MD5Stream with a base stream.
public MD5Stream(Stream baseStream, byte[] expectedHash, long expectedLength)
Parameters
baseStream
StreamStream to calculate hash for.
expectedHash
byte[]Expected hash. Will be compared against calculated hash on stream close. Pass in null to disable check.
expectedLength
longExpected length of the stream. If the reading stops before reaching this position, CalculatedHash will be set to empty array.
Exceptions
- AmazonClientException
Exception thrown during Close() or CalculateHash(), if ExpectedHash is set and is different from CalculateHash that the stream calculates, provided that CalculatedHash is not a zero-length byte array.