FromBase64Transform::TransformFinalBlock Method (array<Byte>^, Int32, Int32)

 

Converts the specified region of the specified byte array from base 64.

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

public:
virtual array<unsigned char>^ TransformFinalBlock(
	array<unsigned char>^ inputBuffer,
	int inputOffset,
	int inputCount
) sealed

Parameters

inputBuffer
Type: array<System::Byte>^

The input to convert from base 64.

inputOffset
Type: System::Int32

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

inputCount
Type: System::Int32

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

Return Value

Type: array<System::Byte>^

The computed conversion.

Exception Condition
ObjectDisposedException

The current FromBase64Transform object has already been disposed.

ArgumentException

inputBuffer has an invalid offset length.

-or-

inputCount has an invalid value.

ArgumentOutOfRangeException

inputOffset is out of range. This parameter requires a non-negative number.

ArgumentNullException

inputBuffer is null.

The following example decrypts a base 64-encoded file to an output text file.

using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;
class MyMainClass
{
public:
   static void DecodeFromFile( String^ inFileName, String^ outFileName )
   {
      FromBase64Transform^ myTransform = gcnew FromBase64Transform( FromBase64TransformMode::IgnoreWhiteSpaces );
      array<Byte>^myOutputBytes = gcnew array<Byte>(myTransform->OutputBlockSize);

      //Open the input and output files.
      FileStream^ myInputFile = gcnew FileStream( inFileName,FileMode::Open,FileAccess::Read );
      FileStream^ myOutputFile = gcnew FileStream( outFileName,FileMode::Create,FileAccess::Write );

      //Retrieve the file contents into a Byte array.
      array<Byte>^myInputBytes = gcnew array<Byte>(myInputFile->Length);
      myInputFile->Read( myInputBytes, 0, myInputBytes->Length );

      //Transform the data in chunks the size of InputBlockSize.
      int i = 0;
      while ( myInputBytes->Length - i > 4 )
      {
         myTransform->TransformBlock( myInputBytes, i, 4, myOutputBytes, 0 );

         /*myTransform->InputBlockSize*/
         i += 4;

         /*myTransform->InputBlockSize*/
         myOutputFile->Write( myOutputBytes, 0, myTransform->OutputBlockSize );
      }


      //Transform the final block of data.
      myOutputBytes = myTransform->TransformFinalBlock( myInputBytes, i, myInputBytes->Length - i );
      myOutputFile->Write( myOutputBytes, 0, myOutputBytes->Length );

      //Free up any used resources.
      myTransform->Clear();
      myInputFile->Close();
      myOutputFile->Close();
   }

};

int main()
{
   MyMainClass * m = new MyMainClass;

   //Insert your file names into this method call.
   m->DecodeFromFile(  "c:\\encoded.txt",  "c:\\roundtrip.txt" );
}

.NET Framework
Available since 1.1
Return to top
Show: