public static ComputeHash ( this stream, ChecksumAlgorithm hashType = ChecksumAlgorithm.SHA256, long maxBodySize = null ) : byte[] | ||
stream | this | the source stream. Use a MemoryStream if uncertain. |
hashType | ChecksumAlgorithm | the Algorithm to use to compute the hash |
maxBodySize | long | |
Résultat | byte[] |
public static byte[] ComputeHash(this Stream stream, ChecksumAlgorithm hashType = ChecksumAlgorithm.SHA256, long? maxBodySize = null)
{
if (stream == null) return null;
using (var algorithm = HashAlgorithm.Create(hashType.ToString()))
if (maxBodySize != null && maxBodySize > 0)
return algorithm.ComputeHash(stream.ReadExactly((long) maxBodySize));
else
return algorithm.ComputeHash(stream);
}
public void ComputeHashNullTest() { Assert.IsNull(ExtensionMethods.ComputeHash(null)); }