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.

[Visual Basic]
Public Overridable Function TransformBlock( _
   ByVal inputBuffer() As Byte, _
   ByVal inputOffset As Integer, _
   ByVal inputCount As Integer, _
   ByVal outputBuffer() As Byte, _
   ByVal outputOffset As Integer _
) As Integer Implements ICryptoTransform.TransformBlock
[C#]
public virtual int TransformBlock(
 byte[] inputBuffer,
 int inputOffset,
 int inputCount,
 byte[] outputBuffer,
 int outputOffset
);
[C++]
public: virtual int TransformBlock(
 unsigned char inputBuffer __gc[],
 int inputOffset,
 int inputCount,
 unsigned char outputBuffer __gc[],
 int outputOffset
);
[JScript]
public function TransformBlock(
   inputBuffer : Byte[],
 inputOffset : int,
 inputCount : int,
 outputBuffer : Byte[],
 outputOffset : int
) : int;

Parameters

inputBuffer
The input for which to compute the hash code.
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
The output to which to write the array.
outputOffset
The offset into the output byte array from which to begin to write.

Return Value

The number of bytes written.

Implements

ICryptoTransform.TransformBlock

Exceptions

Exception Type Condition
System.IO.Exception Input and output buffers are different.

Remarks

This method is used with the TransformFinalBlock method to create a hash of a byte array.

This method takes an input array, an offset, a number of bytes to hash, an output array, and an offset. However, the output array does not contain a copy of the hash but instead contains a copy of the input array. For example, you could use the method as follows:

[C#] 
sha1.TransformBlock(inArray, 0, inArray.Length, inArray, 0);

The following example creates a hash:

[C#] 
byte[] inArray = new ASCIIEncoding().GetBytes("abcdefghijklmnopqrstuvwxyz");
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(inArray, 0, 13, inArray, 0);
md5.TransformFinalBlock(inArray, 13, 13);
   //The value of md5.Hash = { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b };

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HashAlgorithm Class | HashAlgorithm Members | System.Security.Cryptography Namespace | Cryptographic Services

Show:
© 2014 Microsoft