本文整理汇总了C#中System.Security.Cryptography.HashAlgorithm.NullCheck方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.NullCheck方法的具体用法?C# HashAlgorithm.NullCheck怎么用?C# HashAlgorithm.NullCheck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HashAlgorithm
的用法示例。
在下文中一共展示了HashAlgorithm.NullCheck方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hash
/// <summary>
/// Computes the hash of a byte array
/// </summary>
/// <param name="Data">Byte array to hash</param>
/// <param name="Algorithm">Hash algorithm to use (defaults to SHA1)</param>
/// <returns>The hash of the byte array</returns>
public static byte[] Hash(this byte[] Data, HashAlgorithm Algorithm = null)
{
if (Data.IsNull())
return null;
using (HashAlgorithm Hasher = Algorithm.NullCheck(()=>new SHA1CryptoServiceProvider()))
{
byte[] HashedArray = Hasher.ComputeHash(Data);
Hasher.Clear();
return HashedArray;
}
}
示例2: Hash
/// <summary>
/// Computes the hash of a byte array
/// </summary>
/// <param name="data">Byte array to hash</param>
/// <param name="algorithm">Hash algorithm to use (defaults to SHA1)</param>
/// <returns>The hash of the byte array</returns>
public static byte[] Hash(this byte[] data, HashAlgorithm algorithm = null)
{
if (data.IsNull())
return null;
using (HashAlgorithm hasher = algorithm.NullCheck(() => new SHA1CryptoServiceProvider()))
{
byte[] hashedArray = hasher.ComputeHash(data);
hasher.Clear();
return hashedArray;
}
}