FromBase64Transform Class
.NET Framework 3.5
Converts a CryptoStream from base 64.
Assembly: mscorlib (in mscorlib.dll)
The following example decrypts a base 64-encoded file to an output text file.
using System; using System.IO; using System.Security.Cryptography; namespace ToBase64Transform_Examples { class MyMainClass { public static void Main() { //Insert your file names into this method call. DecodeFromFile("c:\\encoded.txt", "c:\\roundtrip.txt"); } public static void DecodeFromFile(string inFileName, string outFileName) { FromBase64Transform myTransform = new FromBase64Transform(FromBase64TransformMode.IgnoreWhiteSpaces); byte[] myOutputBytes = new byte[myTransform.OutputBlockSize]; //Open the input and output files. FileStream myInputFile = new FileStream(inFileName, FileMode.Open, FileAccess.Read); FileStream myOutputFile = new FileStream(outFileName, FileMode.Create, FileAccess.Write); //Retrieve the file contents into a byte array. byte[] myInputBytes = new 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.InputBlockSize*/) { myTransform.TransformBlock(myInputBytes, i, 4/*myTransform.InputBlockSize*/, myOutputBytes, 0); 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(); } } }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.