Export (0) Print
Expand All

HashAlgorithm.TransformFinalBlock Method

Computes the hash value for the specified region of the specified byte array.

Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)

public byte[] TransformFinalBlock (
	byte[] inputBuffer,
	int inputOffset,
	int inputCount
)
public final byte[] TransformFinalBlock (
	byte[] inputBuffer, 
	int inputOffset, 
	int inputCount
)
public final function TransformFinalBlock (
	inputBuffer : byte[], 
	inputOffset : int, 
	inputCount : int
) : byte[]

Parameters

inputBuffer

The input to compute the hash code for.

inputOffset

The offset into the byte array from which to begin using data.

inputCount

The number of bytes in the byte array to use as data.

Return Value

An array that is a copy of the part of the input that is hashed.

You must call the TransformFinalBlock method after calling the TransformBlock method but before you retrieve the final hash value.

Note that the return value of this method is not the hash value, but only a copy of the hashed part of the input data. To retrieve the final hashed value after calling the TransformFinalBlock method, get the byte array contained in the Hash property.

The following code examples use the TransformFinalBlock method with the TransformBlock method to hash a string.

// Use TransformFinalBlock with TransformBlock to hash a string.
byte[] inArray = new ASCIIEncoding().GetBytes("abcdefghijklmnopqrstuvwxyz");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(inArray, 0, 13, inArray, 0);
md5.TransformFinalBlock(inArray, 13, 13);

// Use TransformFinalBlock with TransformBlock to hash a string.
ubyte inArray[] = (new ASCIIEncoding()).GetBytes(
    "abcdefghijklmnopqrstuvwxyz");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(inArray, 0, 13, inArray, 0);
md5.TransformFinalBlock(inArray, 13, 13);

// Hash two strings together.
byte[] inArray1 = new ASCIIEncoding().GetBytes("message ");
byte[] inArray2 = new ASCIIEncoding().GetBytes("digest");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(inArray1, 0, inArray1.Length, inArray1, 0);
md5.TransformFinalBlock(inArray2, 0, inArray2.Length);

// Hash two strings together.
ubyte inArray1[] = (new ASCIIEncoding()).GetBytes("message ");
ubyte inArray2[] = (new ASCIIEncoding()).GetBytes("digest");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(inArray1, 0, inArray1.get_Length(), inArray1, 0);
md5.TransformFinalBlock(inArray2, 0, inArray2.get_Length());

The following code example uses only the TransformFinalBlock method to hash a string.

// Use TransformFinalBlock to hash a string.
byte[] inArray = new ASCIIEncoding().GetBytes("abcdefghijklmnopqrstuvwxyz");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformFinalBlock(inArray, 0, 26);

// Use TransformFinalBlock to hash a string.
ubyte inArray[] = (new ASCIIEncoding()).GetBytes(
    "abcdefghijklmnopqrstuvwxyz");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformFinalBlock(inArray, 0, 26);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft