本文整理汇总了C#中Crc32.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Crc32.Dispose方法的具体用法?C# Crc32.Dispose怎么用?C# Crc32.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crc32
的用法示例。
在下文中一共展示了Crc32.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Verify
/// <summary>
/// Computes the hash for the specified stream and compares
/// it to the value in this object. CRC hashes are not supported
/// because there is no built-in support in the .net framework and
/// a CRC implementation exceeds the scope of this project. If you
/// attempt to Verify() a CRC hash a NotImplemented() exception will
/// be thrown.
/// </summary>
/// <param name="istream">The stream to compute the hash for</param>
/// <returns>True if the computed hash matches what's stored in this object.</returns>
public bool Verify(Stream istream) {
if (IsValid) {
HashAlgorithm hashAlg = null;
switch (m_algorithm) {
case FtpHashAlgorithm.SHA1:
hashAlg = new SHA1CryptoServiceProvider();
break;
#if !NET2
case FtpHashAlgorithm.SHA256:
hashAlg = new SHA256CryptoServiceProvider();
break;
case FtpHashAlgorithm.SHA512:
hashAlg = new SHA512CryptoServiceProvider();
break;
#endif
case FtpHashAlgorithm.MD5:
hashAlg = new MD5CryptoServiceProvider();
break;
case FtpHashAlgorithm.CRC:
hashAlg = new Crc32();
break;
//throw new NotImplementedException("There is no built in support for computing CRC hashes.");
default:
throw new NotImplementedException("Unknown hash algorithm: " + m_algorithm.ToString());
}
try {
byte[] data = null;
string hash = "";
data = hashAlg.ComputeHash(istream);
if (data != null) {
foreach (byte b in data) {
hash += b.ToString("x2");
}
return (hash.ToUpper() == m_value.ToUpper());
}
}
finally {
#if !NET2 // .NET 2.0 doesn't provide access to Dispose() for HashAlgorithm
if (hashAlg != null)
hashAlg.Dispose();
#endif
}
}
return false;
}