当前位置: 首页>>代码示例>>C#>>正文


C# HashAlgorithm.Clear方法代码示例

本文整理汇总了C#中HashAlgorithm.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.Clear方法的具体用法?C# HashAlgorithm.Clear怎么用?C# HashAlgorithm.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashAlgorithm的用法示例。


在下文中一共展示了HashAlgorithm.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrintHash

 // prints the hash of a specified input to the console
 public static void PrintHash(string name, HashAlgorithm algo, byte[] data)
 {
     // compute the hash of the input data..
     byte[] hash = algo.ComputeHash(data);
     // ..and write the hash to the console
     Console.WriteLine(name + BytesToHex(hash));
     // dispose of the hash algorithm; we do not need to hash more data with it
     algo.Clear();
 }
开发者ID:maikgreubel,项目名称:securitylibrary,代码行数:10,代码来源:Hashing.cs

示例2: ExerciseHash

	public static bool ExerciseHash(HashAlgorithm hash, int size)
	{
		// Exercise the properties
		//
		if (hash.CanReuseTransform != true)
		{
			Console.WriteLine("CanReuseTransform != true");
			return false;
		}

		if (hash.CanTransformMultipleBlocks != true)
		{
			Console.WriteLine("CanTransformMultipleBlocks != true");
			return false;
		}

		if (hash.HashSize != size)
		{
			Console.WriteLine("HashSize, expected={0} actual={1}", size, hash.HashSize);
			return false;
		}

		if (hash.InputBlockSize != 1)
		{
			Console.WriteLine("InputBlockSize != 1");
			return false;
		}

		if (hash.OutputBlockSize != 1)
		{
			Console.WriteLine("OutputBlockSize != 1");
			return false;
		}

		// Exercise the Initialize method.  Test proper behavior both when it is and is not called.
		//
		byte[] bytesHalf1 = {0x00, 0x01, 0x02, 0x03};
		byte[] bytesHalf2 = {0xfc, 0xfd, 0xfe, 0xff};
		byte[] bytesFull  = {0x00, 0x01, 0x02, 0x03, 0xfc, 0xfd, 0xfe, 0xff};
		byte[] bytesExpected;
		byte[] bytesActual;

		// Initialize is called between partial hashes
		//
		hash.Initialize();
		bytesExpected = hash.ComputeHash(bytesHalf1);
		
		hash.Initialize();
		hash.TransformBlock(bytesHalf2, 0, bytesHalf2.Length, bytesHalf2, 0);
		hash.Initialize();
		hash.TransformFinalBlock(bytesHalf1, 0, bytesHalf1.Length);
		bytesActual = hash.Hash;

		if (!CompareBytes(bytesExpected, bytesActual))
		{
			Console.WriteLine("\nInitialize test failed");
			return false;
		}

		// Initialize is not called between partial hashes
		//
		hash.Initialize();
		bytesExpected = hash.ComputeHash(bytesFull);

		hash.Initialize();
		hash.TransformBlock(bytesHalf1, 0, bytesHalf1.Length, bytesHalf1, 0);
		hash.TransformFinalBlock(bytesHalf2, 0, bytesHalf2.Length);
		bytesActual = hash.Hash;
		
		if (!CompareBytes(bytesExpected, bytesActual))
		{
			Console.WriteLine("\nNo Initialize test failed");
			return false;
		}

		// Exercise the Clear method -- ensure object disposed
		//
		hash.Initialize();
		hash.Clear();

		try
		{
			hash.ComputeHash(bytesFull);
			Console.WriteLine("Clear test failed -- no exception thrown");
			return false;
		}
		catch (ObjectDisposedException)
		{
		}
		
		return true;
	}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:92,代码来源:SHACSP_CNG_API.cs


注:本文中的HashAlgorithm.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。