本文整理汇总了C#中HashAlgorithm.TransformFinalBlock方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.TransformFinalBlock方法的具体用法?C# HashAlgorithm.TransformFinalBlock怎么用?C# HashAlgorithm.TransformFinalBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashAlgorithm
的用法示例。
在下文中一共展示了HashAlgorithm.TransformFinalBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDigestedBytes
internal byte[] GetDigestedBytes(HashAlgorithm hash) {
m_c14nDoc.WriteHash(hash, DocPosition.BeforeRootElement, m_ancMgr);
hash.TransformFinalBlock(new byte[0], 0, 0);
byte[] res = (byte[]) hash.Hash.Clone();
// reinitialize the hash so it is still usable after the call
hash.Initialize();
return res;
}
示例2: 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);
}
示例3: 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();
}
};
}
示例4: 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;
}