다음을 통해 공유


FromBase64Transform 클래스

64 기수인 CryptoStream을 변환합니다.

네임스페이스: System.Security.Cryptography
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
Public Class FromBase64Transform
    Implements ICryptoTransform, IDisposable
‘사용 방법
Dim instance As FromBase64Transform
[ComVisibleAttribute(true)] 
public class FromBase64Transform : ICryptoTransform, IDisposable
[ComVisibleAttribute(true)] 
public ref class FromBase64Transform : ICryptoTransform, IDisposable
/** @attribute ComVisibleAttribute(true) */ 
public class FromBase64Transform implements ICryptoTransform, IDisposable
ComVisibleAttribute(true) 
public class FromBase64Transform implements ICryptoTransform, IDisposable

설명

64 기수 콘텐츠-전송-인코딩은 임의의 비트 시퀀스를 사용자가 읽을 수 없는 형식으로 표현합니다.

예제

Imports System
Imports System.IO
Imports System.Security.Cryptography

Namespace ToBase64Transform_Examples
    Class MyMainClass
        Public Shared Sub Main()
            'Insert your file names into this method call.
            DecodeFromFile("c:\encoded.txt", "c:\roundtrip.txt")
        End Sub 'Main

        Public Shared Sub DecodeFromFile(ByVal inFileName As String, ByVal outFileName As String)
            Dim myTransform As New FromBase64Transform(FromBase64TransformMode.IgnoreWhiteSpaces)

            Dim myOutputBytes(myTransform.OutputBlockSize - 1) As Byte

            'Open the input and output files.
            Dim myInputFile As New FileStream(inFileName, FileMode.Open, FileAccess.Read)
            Dim myOutputFile As New FileStream(outFileName, FileMode.Create, FileAccess.Write)

            'Retrieve the file contents into a byte array.
            Dim myInputBytes(myInputFile.Length - 1) As Byte
            myInputFile.Read(myInputBytes, 0, myInputBytes.Length)

            'Transform the data in chunks the size of InputBlockSize.
            Dim i As Integer = 0
            While myInputBytes.Length - i > 4 'myTransform.InputBlockSize
                myTransform.TransformBlock(myInputBytes, i, 4, myOutputBytes, 0) 'myTransform.InputBlockSize
                i += 4 'myTransform.InputBlockSize
                myOutputFile.Write(myOutputBytes, 0, myTransform.OutputBlockSize)
            End While

            '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()
        End Sub 'DecodeFromFile
    End Class 'MyMainClass
End Namespace 'ToBase64Transform_Examples
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();
        }
    }
}
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" );
}
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

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

FromBase64Transform 멤버
System.Security.Cryptography 네임스페이스

기타 리소스

암호화 서비스