ToBase64Transformとは? わかりやすく解説

ToBase64Transform クラス

CryptoStream を base 64変換します

名前空間: System.Security.Cryptography
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Class ToBase64Transform
    Implements ICryptoTransform, IDisposable
Dim instance As ToBase64Transform
[ComVisibleAttribute(true)] 
public class ToBase64Transform : ICryptoTransform,
 IDisposable
[ComVisibleAttribute(true)] 
public ref class ToBase64Transform : ICryptoTransform,
 IDisposable
/** @attribute ComVisibleAttribute(true) */ 
public class ToBase64Transform implements ICryptoTransform,
 IDisposable
ComVisibleAttribute(true) 
public class ToBase64Transform implements ICryptoTransform,
 IDisposable
解説解説
使用例使用例

ToBase64Transform クラスメンバ使用する方法次のコード例示します

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

Public Class Form1
    Inherits System.Windows.Forms.Form

    ' Event handler for Run button.
    Private Sub Button1_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles
 Button1.Click

        tbxOutput.Cursor = Cursors.WaitCursor
        tbxOutput.Text = ""

        Dim appPath As String
        appPath = (System.IO.Directory.GetCurrentDirectory() + "\\")

        ' Insert your file names into this method call.
        EncodeFromFile(appPath + "members.vb", appPath
 + "membersvb.enc")

        ' Reset the cursor and conclude application.
        tbxOutput.AppendText(vbCrLf + "This sample completed "
 + _
            "successfully; press Exit to continue.")
        tbxOutput.Cursor = Cursors.Default
    End Sub

    ' Read in the specified source file and write out an encoded target
 file.
    Private Sub EncodeFromFile( _
        ByVal sourceFile As String,
 _
        ByVal targetFile As String)

        ' Verify members.cs exists at the specified directory.
        If (Not File.Exists(sourceFile)) Then
            tbxOutput.AppendText("Unable to locate source file
 located at ")
            tbxOutput.AppendText(sourceFile + ". Please correct
 the path ")
            tbxOutput.AppendText("and run the sample again.")

            Exit Sub
        End If

        ' Retrieve the input and output file streams.
        Dim inputFileStream As New
 FileStream( _
            sourceFile, FileMode.Open, FileAccess.Read)
        Dim outputFileStream As New
 FileStream( _
            targetFile, FileMode.Create, FileAccess.Write)

        ' Create a new ToBase64Transform object to convert to base 64.
        Dim base64Transform As New
 ToBase64Transform

        ' Create a new byte array with the size of the output block
 size.
        Dim outputBytes(base64Transform.OutputBlockSize) As
 Byte

        ' Retrieve the file contents into a byte array.
        Dim inputBytes(inputFileStream.Length) As
 Byte
        inputFileStream.Read(inputBytes, 0, inputBytes.Length)

        ' Verify that multiple blocks can not be transformed.
        If (Not base64Transform.CanTransformMultipleBlocks)
 Then
            ' Initializie the offset size.
            Dim inputOffset As Integer
 = 0

            ' Iterate through inputBytes transforming by blockSize.
            Dim inputBlockSize As Integer
 = base64Transform.InputBlockSize

            While (inputBytes.Length - inputOffset > inputBlockSize)
                base64Transform.TransformBlock( _
                    inputBytes, _
                    inputOffset, _
                    inputBytes.Length - inputOffset, _
                    outputBytes, _
                    0)

                inputOffset += base64Transform.InputBlockSize
                outputFileStream.Write(outputBytes, _
                    0, _
                    base64Transform.OutputBlockSize)
            End While

            ' Transform the final block of data.
            outputBytes = base64Transform.TransformFinalBlock( _
                inputBytes, _
                inputOffset, _
                inputBytes.Length - inputOffset)

            outputFileStream.Write(outputBytes, 0, outputBytes.Length)
            tbxOutput.AppendText("Created encoded file at "
 + targetFile)
        End If

        ' Determine if the current transform can be reused.
        If (Not base64Transform.CanReuseTransform)
 Then
            ' Free up any used resources.
            base64Transform.Clear()
        End If

        ' Close file streams.
        inputFileStream.Close()
        outputFileStream.Close()
    End Sub

    ' Event handler for Exit button.
    Private Sub Button2_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles
 Button2.Click

        Application.Exit()
    End Sub
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides
 Sub Dispose(ByVal disposing As
 Boolean)
        If disposing Then
            If Not (components Is
 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel2 As
 System.Windows.Forms.Panel
    Friend WithEvents Panel1 As
 System.Windows.Forms.Panel
    Friend WithEvents Button1 As
 System.Windows.Forms.Button
    Friend WithEvents Button2 As
 System.Windows.Forms.Button
    Friend WithEvents tbxOutput As
 System.Windows.Forms.RichTextBox
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.tbxOutput = New System.Windows.Forms.RichTextBox
        Me.Panel2.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel2
        '
        Me.Panel2.Controls.Add(Me.Button1)
        Me.Panel2.Controls.Add(Me.Button2)
        Me.Panel2.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Panel2.DockPadding.All = 20
        Me.Panel2.Location = New System.Drawing.Point(0,
 320)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(616,
 64)
        Me.Panel2.TabIndex = 1
        '
        'Button1
        '
        Me.Button1.Dock = System.Windows.Forms.DockStyle.Right
        Me.Button1.Font = New System.Drawing.Font(
 _
            "Microsoft Sans Serif", _
            9.0!, _
            System.Drawing.FontStyle.Regular, _
            System.Drawing.GraphicsUnit.Point, _
            CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(446,
 20)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75,
 24)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "&Run"
        '
        'Button2
        '
        Me.Button2.Dock = System.Windows.Forms.DockStyle.Right
        Me.Button2.Font = New System.Drawing.Font(
 _
            "Microsoft Sans Serif", _
            9.0!, _
            System.Drawing.FontStyle.Regular, _
            System.Drawing.GraphicsUnit.Point, _
            CType(0, Byte))
        Me.Button2.Location = New System.Drawing.Point(521,
 20)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(75,
 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "E&xit"
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.tbxOutput)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.DockPadding.All = 20
        Me.Panel1.Location = New System.Drawing.Point(0,
 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(616,
 320)
        Me.Panel1.TabIndex = 2
        '
        'tbxOutput
        '
        Me.tbxOutput.AccessibleDescription = _
            "Displays output from application."
        Me.tbxOutput.AccessibleName = "Output
 textbox."
        Me.tbxOutput.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tbxOutput.Location = New System.Drawing.Point(20,
 20)
        Me.tbxOutput.Name = "tbxOutput"
        Me.tbxOutput.Size = New System.Drawing.Size(576,
 280)
        Me.tbxOutput.TabIndex = 1
        Me.tbxOutput.Text = "Click the Run
 button to run the application."
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6,
 15)
        Me.ClientSize = New System.Drawing.Size(616,
 384)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Panel2)
        Me.Name = "Form1"
        Me.Text = "ToBase64Transform"
        Me.Panel2.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
End Class
'
' This sample produces the following output:
'
' Created encoded file at C:\WindowsApplication1\\membersvb.enc
' This sample completed successfully; press Exit to continue.
using System;
using System.IO;
using System.Security.Cryptography;

class Members
{
    [STAThread]
    static void Main(string[]
 args)
    {
        string appPath = (System.IO.Directory.GetCurrentDirectory()
 + "\\");

        // Insert your file names into this method call.
        EncodeFromFile(appPath + "members.cs", appPath + "members.enc");

        Console.WriteLine("This sample completed successfully; " +
            "press Enter to exit.");
        Console.ReadLine();
    }

    // Read in the specified source file and write out an encoded target
 file.
    private static void
 EncodeFromFile(string sourceFile, string
 targetFile) 
    {
        // Verify members.cs exists at the specified directory.
        if (!File.Exists(sourceFile))
        {
            Console.Write("Unable to locate source file located at ");
            Console.WriteLine(sourceFile + ".");
            Console.Write("Please correct the path and run the ");
            Console.WriteLine("sample again.");
            return;
        }

        // Retrieve the input and output file streams.
        FileStream inputFileStream = 
            new FileStream(sourceFile, FileMode.Open, FileAccess.Read);
        FileStream outputFileStream = 
            new FileStream(targetFile, FileMode.Create, FileAccess.Write);

        // Create a new ToBase64Transform object to convert to base
 64.
        ToBase64Transform base64Transform = new ToBase64Transform();

        // Create a new byte array with the size of the output block
 size.
        byte[] outputBytes = new byte[base64Transform.OutputBlockSize];

        // Retrieve the file contents into a byte array.
        byte[] inputBytes = new byte[inputFileStream.Length];
        inputFileStream.Read(inputBytes, 0, inputBytes.Length);

        // Verify that multiple blocks can not be transformed.
        if (!base64Transform.CanTransformMultipleBlocks)
        {
            // Initializie the offset size.
            int inputOffset = 0;

            // Iterate through inputBytes transforming by blockSize.
            int inputBlockSize = base64Transform.InputBlockSize;

            while(inputBytes.Length - inputOffset > inputBlockSize)
            {
                base64Transform.TransformBlock(
                    inputBytes,
                    inputOffset,
                    inputBytes.Length - inputOffset,
                    outputBytes,
                    0);

                inputOffset += base64Transform.InputBlockSize;
                outputFileStream.Write(
                    outputBytes, 
                    0, 
                    base64Transform.OutputBlockSize);
            }

            // Transform the final block of data.
            outputBytes = base64Transform.TransformFinalBlock(
                inputBytes,
                inputOffset,
                inputBytes.Length - inputOffset);

            outputFileStream.Write(outputBytes, 0, outputBytes.Length);
            Console.WriteLine("Created encoded file at " + targetFile);
        }

        // Determine if the current transform can be reused.
        if (! base64Transform.CanReuseTransform)
        {
            // Free up any used resources.
            base64Transform.Clear();
        }

        // Close file streams.
        inputFileStream.Close();
        outputFileStream.Close();
    }
}
//
// This sample produces the following output:
//
// Created encoded file at C:\ConsoleApplication1\\membersvcs.enc
// This sample completed successfully; press Enter to exit.
using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;

ref class Members
{
public:
   [STAThread]
   static void Main()
   {
      String^ appPath = (String::Concat(
         System::IO::Directory::GetCurrentDirectory(), L"\\" ));
      
      // Insert your file names into this method call.
      EncodeFromFile( String::Concat( appPath, L"members.cpp" ),
         String::Concat( appPath, L"members.enc" ) );
      Console::WriteLine( L"This sample completed successfully; "
         L"press Enter to exit." );
      Console::ReadLine();
   }

private:
   // Read in the specified source file and write out an encoded target
 file.
   static void EncodeFromFile( String^ sourceFile,
 String^ targetFile )
   {
      // Verify members.cpp exists at the specified directory.
      if (  !File::Exists( sourceFile ) )
      {
         Console::Write( L"Unable to locate source file located at " );
         Console::WriteLine( L"{0}.", sourceFile );
         Console::Write( L"Please correct the path and run the " );
         Console::WriteLine( L"sample again." );
         return;
      }

      // Retrieve the input and output file streams.
      FileStream^ inputFileStream = gcnew FileStream(
         sourceFile,FileMode::Open,FileAccess::Read );
      FileStream^ outputFileStream = gcnew FileStream(
         targetFile,FileMode::Create,FileAccess::Write );

      // Create a new ToBase64Transform object to convert to base 64.
      ToBase64Transform^ base64Transform = gcnew ToBase64Transform;

      // Create a new byte array with the size of the output block size.
      array<Byte>^outputBytes = gcnew array<Byte>(
         base64Transform->OutputBlockSize);

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

      // Verify that multiple blocks can not be transformed.
      if (  !base64Transform->CanTransformMultipleBlocks )
      {
         // Initializie the offset size.
         int inputOffset = 0;

         // Iterate through inputBytes transforming by blockSize.
         int inputBlockSize = base64Transform->InputBlockSize;
         while ( inputBytes->Length - inputOffset > inputBlockSize
 )
         {
            base64Transform->TransformBlock(
               inputBytes,
               inputOffset,
               inputBytes->Length - inputOffset,
               outputBytes,
               0 );

            inputOffset += base64Transform->InputBlockSize;
            outputFileStream->Write(
               outputBytes,
               0,
               base64Transform->OutputBlockSize );
         }
         
         // Transform the final block of data.
         outputBytes = base64Transform->TransformFinalBlock(
            inputBytes,
            inputOffset,
            inputBytes->Length - inputOffset );
         outputFileStream->Write( outputBytes, 0, outputBytes->Length );
         Console::WriteLine( L"Created encoded file at {0}", targetFile
 );
      }

      // Determine if the current transform can be reused.
      if (  !base64Transform->CanReuseTransform )
      {
         // Free up any used resources.
         base64Transform->Clear();
      }

      // Close file streams.
      inputFileStream->Close();
      outputFileStream->Close();
   }
};

int main()
{
   Members::Main();
}

//
// This sample produces the following output:
//
// Created encoded file at C:\ConsoleApplication1\\membersvcs.enc
// This sample completed successfully; press Enter to exit.
import System.*;
import System.IO.*;
import System.Security.Cryptography.*;

class Members
{
    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        String appPath = System.IO.Directory.GetCurrentDirectory() + "\\";
        // Insert your file names into this method call.
        EncodeFromFile(appPath + "members.cs", appPath + "members.enc");
        Console.WriteLine("This sample completed successfully; " 
            + "press Enter to exit.");
        Console.ReadLine();
    } //main

    // Read in the specified source file and write out an encoded target
 file.
    private static void
 EncodeFromFile(String sourceFile, String targetFile)
    {
        // Verify members.cs exists at the specified directory.
        if (!(File.Exists(sourceFile))) {
            Console.Write("Unable to locate source file located at ");
            Console.WriteLine(sourceFile + ".");
            Console.Write("Please correct the path and run the ");
            Console.WriteLine("sample again.");
            return;
        }
        // Retrieve the input and output file streams.
        FileStream inputFileStream = new FileStream(sourceFile,
 
            FileMode.Open, FileAccess.Read);
        FileStream outputFileStream = new FileStream(targetFile,
 
            FileMode.Create, FileAccess.Write);
        // Create a new ToBase64Transform object to convert to base
 64.
        ToBase64Transform base64Transform = new ToBase64Transform();

        // Create a new byte array with the size of the output block
 size.
        ubyte outputBytes[] = new ubyte[base64Transform.get_OutputBlockSize()];

        // Retrieve the file contents into a byte array.
        ubyte inputBytes[] = new ubyte[(ubyte)inputFileStream.get_Length()];
        inputFileStream.Read(inputBytes, 0, inputBytes.get_Length());
        
        // Verify that multiple blocks can not be transformed.
        if (!(base64Transform.get_CanTransformMultipleBlocks()))
 {
            // Initializie the offset size.
            int inputOffset = 0;
            // Iterate through inputBytes transforming by blockSize.
            int inputBlockSize = base64Transform.get_InputBlockSize();
            while (inputBytes.get_Length() - inputOffset >
 inputBlockSize) {
                base64Transform.TransformBlock(inputBytes, inputOffset, 
                    inputBytes.get_Length() - inputOffset, outputBytes, 0);
                inputOffset += base64Transform.get_InputBlockSize();
                outputFileStream.Write(outputBytes, 0, base64Transform.
                    get_OutputBlockSize());
            }

            // Transform the final block of data.
            outputBytes = base64Transform.TransformFinalBlock(inputBytes, 
                inputOffset, inputBytes.get_Length() - inputOffset);

            outputFileStream.Write(outputBytes, 0, outputBytes.get_Length());
            Console.WriteLine("Created encoded file at " + targetFile);
        }
        // Determine if the current transform can be reused.
        if (!(base64Transform.get_CanReuseTransform())) {
            // Free up any used resources.
            base64Transform.Clear();
        }
        // Close file streams.
        inputFileStream.Close();
        outputFileStream.Close();
    } //EncodeFromFile
} //Members
//
// This sample produces the following output:
//
// Created encoded file at C:\ConsoleApplication1\\membersvcs.enc
// This sample completed successfully; press Enter to exit.
継承階層継承階層
System.Object
  System.Security.Cryptography.ToBase64Transform
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ToBase64Transform コンストラクタ


ToBase64Transform プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CanReuseTransform 現在の変換再利用できるかどうかを示す値を取得します
パブリック プロパティ CanTransformMultipleBlocks 複数ブロック変換できるかどうかを示す値を取得します
パブリック プロパティ InputBlockSize 入力ブロック サイズ取得します
パブリック プロパティ OutputBlockSize 出力ブロック サイズ取得します
参照参照

関連項目

ToBase64Transform クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

ToBase64Transform メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド Dispose ToBase64Transform によって使用されているアンマネージ リソース解放しオプションマネージ リソース解放します。
プロテクト メソッド Finalize オーバーライドされますToBase64Transform によって使用されているアンマネージ リソース解放します。
プロテクト メソッド MemberwiseClone  現在の Object簡易コピー作成します。 ( Object から継承されます。)
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose ToBase64Transform によって使用されているアンマネージ リソース解放します。
参照参照

関連項目

ToBase64Transform クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

ToBase64Transform メンバ

CryptoStream を base 64変換します

ToBase64Transform データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ToBase64Transform ToBase64Transform クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CanReuseTransform 現在の変換再利用できるかどうかを示す値を取得します
パブリック プロパティ CanTransformMultipleBlocks 複数ブロック変換できるかどうかを示す値を取得します
パブリック プロパティ InputBlockSize 入力ブロック サイズ取得します
パブリック プロパティ OutputBlockSize 出力ブロック サイズ取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド Dispose ToBase64Transform によって使用されているアンマネージ リソース解放しオプションマネージ リソース解放します。
プロテクト メソッド Finalize オーバーライドされますToBase64Transform によって使用されているアンマネージ リソース解放します。
プロテクト メソッド MemberwiseClone  現在の Object簡易コピー作成します。 (Object から継承されます。)
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose ToBase64Transform によって使用されているアンマネージ リソース解放します。
参照参照

関連項目

ToBase64Transform クラス
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ToBase64Transform」の関連用語

ToBase64Transformのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ToBase64Transformのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS