ToBase64Transform.TransformBlock Method (Byte[], Int32, Int32, Byte[], Int32)

 

Converts the specified region of the input byte array to base 64 and copies the result 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
)

Parameters

inputBuffer
Type: System.Byte[]

The input to compute to base 64.

inputOffset
Type: System.Int32

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

inputCount
Type: System.Int32

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

outputBuffer
Type: System.Byte[]

The output to which to write the result.

outputOffset
Type: System.Int32

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

Return Value

Type: System.Int32

The number of bytes written.

Exception Condition
ObjectDisposedException

The current ToBase64Transform object has already been disposed.

CryptographicException

The data size is not valid.

ArgumentException

The inputBuffer parameter contains an invalid offset length.

-or-

The inputCount parameter contains an invalid value.

ArgumentNullException

The inputBuffer parameter is null.

ArgumentOutOfRangeException

The inputBuffer parameter requires a non-negative number.

The ToBase64Transform class is a block algorithm that processes input blocks of 3 bytes and creates output blocks of 4 bytes. The TransformBlock method transforms an input block of 24 bits into 32 bits of character data. You must maintain 3 byte input boundaries to 4 byte output boundaries in order to match the block transform.

The following code example demonstrates how to call the TransformBlock method to iterate through inputBytes transforming by blockSize. This code example is part of a larger example provided for the ToBase64Transform class.

int inputBlockSize = base64Transform.InputBlockSize;

while(inputBytes.Length - inputOffset > inputBlockSize)
{
    base64Transform.TransformBlock(
        inputBytes,
        inputOffset,
        inputBytes.Length - inputOffset,
        outputBytes,
        0);

    inputOffset += base64Transform.InputBlockSize;
    outputFileStream.Write(
        outputBytes, 
        0, 
        base64Transform.OutputBlockSize);
}

.NET Framework
Available since 1.1
Return to top
Show: