FromBase64Transform::TransformBlock Method (array<Byte>^, Int32, Int32, array<Byte>^, Int32)
.NET Framework (current version)
Converts the specified region of the input byte array from base 64 and copies the result to the specified region of the output byte array.
Assembly: mscorlib (in mscorlib.dll)
public: virtual int TransformBlock( array<unsigned char>^ inputBuffer, int inputOffset, int inputCount, array<unsigned char>^ outputBuffer, int outputOffset ) sealed
Parameters
- inputBuffer
-
Type:
array<System::Byte>^
The input to compute from 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:
array<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.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The current FromBase64Transform object has already been disposed. |
| ArgumentException | inputCount uses an invalid value. -or- inputBuffer has an invalid offset length. |
| 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
Available since 1.1
Show: