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


C# HashAlgorithm.TransformBlock方法代码示例

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


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

示例1: Speed

 static void Speed(HashAlgorithm digest, int block)
 {
     byte[] input = new byte [block];
     byte[] output = new byte [block];
     DateTime now = DateTime.UtcNow;
     long size = 0;
     while ((DateTime.UtcNow - now).TotalSeconds < 30) {
         digest.TransformBlock (input, 0, input.Length, output, 0);
         size += input.Length;
     }
     digest.TransformFinalBlock (input, 0, input.Length);
     size += input.Length;
     double speed = size / (DateTime.UtcNow - now).TotalSeconds;
     Console.WriteLine ("{0}: {1}: {2} Mbytes/sec", block, digest, speed / 1024 / 1024);
 }
开发者ID:symform,项目名称:crimson,代码行数:15,代码来源:hashperf.cs

示例2: HashStream

    public HashStream(HashAlgorithm algorithm, IUVStream stream)
    {
        HashAlgorithm = algorithm;
        Stream = stream;

        Stream.Data += ((b) => {
            HashAlgorithm.TransformBlock(b.Array, b.Offset, b.Count, null, 0);
        });

        Stream.Complete += () => {
            HashAlgorithm.TransformFinalBlock(new byte[] { }, 0, 0);
            Hash = HashAlgorithm.Hash;
            if (Complete != null) {
                Complete();
            }
        };
    }
开发者ID:oskarwkarlsson,项目名称:LibuvSharp,代码行数:17,代码来源:HashStream.cs

示例3: 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

示例4: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc) {
     if (IsInNodeSet) {
         UTF8Encoding utf8 = new UTF8Encoding(false);
         byte[] rgbData = utf8.GetBytes(Utils.EscapeCData(this.Data));
         hash.TransformBlock(rgbData, 0, rgbData.Length, rgbData, 0);
     }
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:C14NUtil.cs


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