Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FromBase64Transform Class

Converts a CryptoStream from base 64.

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

[ComVisibleAttribute(true)] 
public class FromBase64Transform : ICryptoTransform, IDisposable
/** @attribute ComVisibleAttribute(true) */ 
public class FromBase64Transform implements ICryptoTransform, IDisposable
ComVisibleAttribute(true) 
public class FromBase64Transform implements ICryptoTransform, IDisposable

Base 64 Content-Transfer-Encoding represents arbitrary bit sequences in a form that is not human readable.

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();
        }
    }
}

package ToBase64Transform_Examples; 
import System.*;
import System.IO.*;
import System.Security.Cryptography.*;

class MyMainClass
{
    public static void main(String[] args)
    {
        // Insert your file names into this method call.
        DecodeFromFile("c:\\encoded.txt", "c:\\roundtrip.txt");
    } //main

    public static void DecodeFromFile(String inFileName, String outFileName)
    {
        FromBase64Transform myTransform = 
            new FromBase64Transform(FromBase64TransformMode.IgnoreWhiteSpaces);
        ubyte myOutputBytes[] = new ubyte[myTransform.get_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.
        // const int temp = 2;
        ubyte myInputBytes[] = 
            new ubyte[(new Long(myInputFile.get_Length())).intValue()];
        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.get_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();
    } //DecodeFromFile
} //MyMainClass   

System.Object
  System.Security.Cryptography.FromBase64Transform
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.