Export (0) Print
Expand All

HashAlgorithm.TransformBlock Method

Computes the hash value for the specified region of the input byte array and copies the resulting hash value to the specified region of the output byte array.

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

public int TransformBlock (
	byte[] inputBuffer,
	int inputOffset,
	int inputCount,
	byte[] outputBuffer,
	int outputOffset
)
public final int TransformBlock (
	byte[] inputBuffer, 
	int inputOffset, 
	int inputCount, 
	byte[] outputBuffer, 
	int outputOffset
)
public final function TransformBlock (
	inputBuffer : byte[], 
	inputOffset : int, 
	inputCount : int, 
	outputBuffer : byte[], 
	outputOffset : int
) : int

Parameters

inputBuffer

The input to compute the hash code for.

inputOffset

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

inputCount

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

outputBuffer

A copy of the part of the input array used to compute the hash code.

outputOffset

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

Return Value

The number of bytes written.

You must call the TransformBlock method before calling the TransformFinalBlock method. You must call both methods before you retrieve the final hash value.

To retrieve the final hash value after calling the TransformFinalBlock method, get the byte array contained within the Hash property.

Calling the TransformBlock method with different input and output arrays results in an IOException.

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());

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