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

RijndaelManagedTransform クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

Rijndael アルゴリズム使用してデータ暗号変換実行します。このクラス継承できません。

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

<ComVisibleAttribute(True)> _
Public NotInheritable Class
 RijndaelManagedTransform
    Implements ICryptoTransform, IDisposable
Dim instance As RijndaelManagedTransform
[ComVisibleAttribute(true)] 
public sealed class RijndaelManagedTransform
 : ICryptoTransform, IDisposable
[ComVisibleAttribute(true)] 
public ref class RijndaelManagedTransform sealed
 : ICryptoTransform, IDisposable
/** @attribute ComVisibleAttribute(true) */ 
public final class RijndaelManagedTransform
 implements ICryptoTransform, IDisposable
ComVisibleAttribute(true) 
public final class RijndaelManagedTransform
 implements ICryptoTransform, IDisposable
解説解説

CreateEncryptor メソッドおよび CreateDecryptor メソッドどちらも現在の RijndaelManaged オブジェクトキー情報初期化された RijndaelManagedTransform クラスインスタンス返しますRijndael アルゴリズム使用してデータ暗号化または復号化するには、これらのメソッドから返されRijndaelManagedTransform オブジェクトを CryptoStream オブジェクト渡します

使用例使用例

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

Imports System
Imports System.Security.Cryptography
Imports System.Collections
Imports System.Text



Class Members
    ' Use a RijndaelManaged object for encryption and decryption.
    Private Shared rij As
 New RijndaelManaged()


    <STAThread()> _
    Shared Sub Main(ByVal
 args() As String)
        Dim message As String
 = "012345678901234567890"
        Dim sourceBytes As Byte()
 = Encoding.ASCII.GetBytes(message)
        Console.WriteLine("** Phrase to be encoded: "
 + message)

        Dim encodedBytes As Byte()
 = EncodeBytes(sourceBytes)
        Console.WriteLine("** Phrase after encoding: "
 + Encoding.ASCII.GetString(encodedBytes))

        Dim decodedBytes As Byte()
 = DecodeBytes(encodedBytes)
        Console.WriteLine("** Phrase after decoding: "
 + Encoding.ASCII.GetString(decodedBytes))

        Console.WriteLine("Sample ended successfully; "
 + "press Enter to continue.")
        Console.ReadLine()

    End Sub 'Main


    ' Encode the specified byte array by using RijndaelManagedTransform.
    Private Shared Function
 EncodeBytes(ByVal sourceBytes() As Byte)
 As Byte()
        Dim currentPosition As Integer
 = 0
        Dim targetBytes(1023) As Byte
        Dim sourceByteLength As Integer
 = sourceBytes.Length

        ' Create a Rijndael encryptor from this instance to perform
 encryption.
        Dim rijTransform As RijndaelManagedTransform
 = CType(rij.CreateEncryptor(), RijndaelManagedTransform)

        ' Retrieve the block size to read the bytes.
        Dim inputBlockSize As Integer
 = rijTransform.InputBlockSize
        ' Retrieve the block size to write the bytes.
        Dim outputBlockSize As Integer
 = rijTransform.OutputBlockSize
        Try
            ' Determine if multiple blocks can be transformed.
            If rijTransform.CanTransformMultipleBlocks Then
                Dim numBytesRead As Integer
 = 0
                While sourceByteLength - currentPosition >=
 inputBlockSize
                    ' Transform the bytes from currentPosition in the
                    ' sourceBytes array, writing the bytes to the targetBytes
                    ' array.
                    numBytesRead = rijTransform.TransformBlock(sourceBytes, currentPosition,
 inputBlockSize, targetBytes, currentPosition)
                    ' Advance the current position in the sourceBytes
 array.
                    currentPosition += numBytesRead
                End While

                ' Transform the final block of bytes.
                Dim finalBytes As Byte()
 = rijTransform.TransformFinalBlock(sourceBytes, currentPosition, sourceByteLength
 - currentPosition)
                ' Copy the contents of the finalBytes array to the
                ' targetBytes array.
                finalBytes.CopyTo(targetBytes, currentPosition)
            End If

        Catch ex As Exception
            Console.WriteLine("Caught unexpected exception:"
 + ex.ToString())
        End Try

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

        ' Trim the extra bytes in the array that were not used.
        Return TrimArray(targetBytes)

    End Function 'EncodeBytes


    ' Decode the specified byte array using RijndaelManagedTransform.
    Private Shared Function
 DecodeBytes(ByVal sourceBytes() As Byte)
 As Byte()
        Dim targetBytes(1023) As Byte
        Dim currentPosition As Integer
 = 0

        ' Create a Rijndael decryptor from this instance to perform
 decryption.
        Dim rijTransform As RijndaelManagedTransform
 = CType(rij.CreateDecryptor(), RijndaelManagedTransform)

        Dim inputBlockSize As Integer
 = rijTransform.InputBlockSize
        ' Compensate for VB padding of arrays.
        Dim sourceByteLength As Integer
 = sourceBytes.Length - 1

        Try
            Dim numBytesRead As Integer
 = 0
            While sourceByteLength - currentPosition >= inputBlockSize
                ' Transform the bytes from currentposition in the 
                ' sourceBytes array, writing the bytes to the targetBytes
                ' array.
                numBytesRead = rijTransform.TransformBlock(sourceBytes, currentPosition,
 inputBlockSize, targetBytes, currentPosition)

                ' Advance the current position in the source array.
                currentPosition += numBytesRead
            End While

            ' Transform the final block of bytes.
            Dim finalBytes As Byte()
 = rijTransform.TransformFinalBlock(sourceBytes, currentPosition, sourceByteLength
 - currentPosition)

            ' Copy the contents of the finalBytes array to the targetBytes
            ' array.
            finalBytes.CopyTo(targetBytes, currentPosition)
        Catch ex As Exception
            Console.WriteLine("Caught unexpected exception:"
 + ex.ToString())
        End Try

        ' Trim the extra bytes in the array that were not used.
        Return TrimArray(targetBytes)

    End Function 'DecodeBytes


    ' Resize the dimensions of the array to a size that contains only
 valid
    ' bytes.
    Private Shared Function
 TrimArray(ByVal targetArray() As Byte)
 As Byte()
        Dim enum1 As IEnumerator = targetArray.GetEnumerator()
        Dim i As Integer
 = 0

        While enum1.MoveNext()
            If enum1.Current.ToString().Equals("0")
 Then
                Exit While
            End If
            i += 1
        End While

        ' Create a new array with the number of valid bytes.
        Dim returnedArray(i) As Byte
        Dim j As Integer
        For j = 0 To i
            returnedArray(j) = targetArray(j)
        Next j

        Return returnedArray

    End Function 'TrimArray
End Class 'Members
using System;
using System.Security.Cryptography;
using System.Collections;
using System.Text;

class Members
{
    // Use a RijndaelManaged object for encryption and decryption.
    static RijndaelManaged rij = new RijndaelManaged();

    [STAThread]
    static void Main(string[]
 args)
    {
        string message = "012345678901234567890";
        byte[] sourceBytes = Encoding.ASCII.GetBytes(message);
        Console.WriteLine("** Phrase to be encoded: " + message);

        byte[] encodedBytes = EncodeBytes(sourceBytes);
        Console.WriteLine("** Phrase after encoding: " +
            Encoding.ASCII.GetString(encodedBytes));

        byte[] decodedBytes = DecodeBytes(encodedBytes);
        Console.WriteLine("** Phrase after decoding: " +
            Encoding.ASCII.GetString(decodedBytes));

        Console.WriteLine("Sample ended successfully; " +
            "press Enter to continue.");
        Console.ReadLine();
    }

    // Encode the specified byte array by using RijndaelManagedTransform.
    private static byte[] EncodeBytes(byte[]
 sourceBytes)
    {
        int currentPosition = 0;
        byte[] targetBytes = new byte[1024];
        int sourceByteLength = sourceBytes.Length;

        // Create a Rijndael encryptor from this instance to perform
 encryption.
        RijndaelManagedTransform rijTransform =
            (RijndaelManagedTransform)rij.CreateEncryptor();

        // Retrieve the block size to read the bytes.
        int inputBlockSize = rijTransform.InputBlockSize;
        // Retrieve the block size to write the bytes.
        int outputBlockSize = rijTransform.OutputBlockSize;

        try
        {
            // Determine if multiple blocks can be transformed.
            if (rijTransform.CanTransformMultipleBlocks)
            {
                int numBytesRead = 0;
                while (sourceByteLength - currentPosition >=
 inputBlockSize)
                {
                    // Transform the bytes from currentPosition in the
                    // sourceBytes array, writing the bytes to the targetBytes
                    // array.
                    numBytesRead = rijTransform.TransformBlock(
                        sourceBytes,
                        currentPosition,
                        inputBlockSize,
                        targetBytes,
                        currentPosition);

                    // Advance the current position in the sourceBytes
 array.
                    currentPosition += numBytesRead;
                }

                // Transform the final block of bytes.
                byte[] finalBytes = rijTransform.TransformFinalBlock(
                    sourceBytes,
                    currentPosition,
                    sourceByteLength - currentPosition);

                // Copy the contents of the finalBytes array to the
                // targetBytes array.
                finalBytes.CopyTo(targetBytes, currentPosition);
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine("Caught unexpected exception:" + ex.ToString());
        }

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

        // Trim the extra bytes in the array that were not used.
        return TrimArray(targetBytes);
    }

    // Decode the specified byte array using RijndaelManagedTransform.
    private static byte[] DecodeBytes(byte[]
 sourceBytes)
    {
        byte[] targetBytes = new byte[1024];
        int currentPosition = 0;

        // Create a Rijndael decryptor from this instance to perform
 decryption.
        RijndaelManagedTransform rijTransform =
            (RijndaelManagedTransform)rij.CreateDecryptor();

        int inputBlockSize = rijTransform.InputBlockSize;
        int sourceByteLength = sourceBytes.Length;

        try
        {
            int numBytesRead = 0;
            while (sourceByteLength - currentPosition >= inputBlockSize)
            {
                // Transform the bytes from currentposition in the 
                // sourceBytes array, writing the bytes to the targetBytes
                // array.
                numBytesRead = rijTransform.TransformBlock(
                    sourceBytes,
                    currentPosition,
                    inputBlockSize,
                    targetBytes,
                    currentPosition);

                // Advance the current position in the source array.
                currentPosition += numBytesRead;
            }

            // Transform the final block of bytes.
            byte[] finalBytes = rijTransform.TransformFinalBlock(
                sourceBytes,
                currentPosition,
                sourceByteLength - currentPosition);

            // Copy the contents of the finalBytes array to the targetBytes
            // array.
            finalBytes.CopyTo(targetBytes, currentPosition);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Caught unexpected exception:" + ex.ToString());
        }

        // Trim the extra bytes in the array that were not used.
        return TrimArray(targetBytes);
    }

    // Resize the dimensions of the array to a size that contains only
 valid
    // bytes.
    private static byte[] TrimArray(byte[]
 targetArray)
    {
        IEnumerator enum1 = targetArray.GetEnumerator();
        int i = 0;

        while (enum1.MoveNext())
        {
            if (enum1.Current.ToString().Equals("0"))
            {
                break;
            }
            i++;
        }

        // Create a new array with the number of valid bytes.
        byte[] returnedArray = new byte[i];
        for (int j = 0; j < i; j++)
        {
            returnedArray[j] = targetArray[j];
        }

        return returnedArray;
    }
}
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Collections;
using namespace System::Text;

ref class Members
{
private:
   // Use a RijndaelManaged object for encryption and decryption.
   static RijndaelManaged^ rij = gcnew RijndaelManaged;

public:
   [STAThread]
   static void Main()
   {
      String^ message = L"012345678901234567890";
      array<Byte>^sourceBytes = Encoding::ASCII->GetBytes( message );
      Console::WriteLine( L"** Phrase to be encoded: {0}", message );
      array<Byte>^encodedBytes = EncodeBytes( sourceBytes );
      Console::WriteLine( L"** Phrase after encoding: {0}",
         Encoding::ASCII->GetString( encodedBytes ) );
      array<Byte>^decodedBytes = DecodeBytes( encodedBytes );
      Console::WriteLine( L"** Phrase after decoding: {0}",
         Encoding::ASCII->GetString( decodedBytes ) );
      Console::WriteLine( L"Sample ended successfully; "
         L"press Enter to continue." );
      Console::ReadLine();
   }

private:

   // Encode the specified byte array by using RijndaelManagedTransform.
   static array<Byte>^ EncodeBytes( array<Byte>^sourceBytes
 )
   {
      int currentPosition = 0;
      array<Byte>^targetBytes = gcnew array<Byte>(1024);
      int sourceByteLength = sourceBytes->Length;

      // Create a Rijndael encryptor from this instance to perform encryption.
      RijndaelManagedTransform^ rijTransform =
         static_cast<RijndaelManagedTransform^>(rij->CreateEncryptor());

      // Retrieve the block size to read the bytes.
      int inputBlockSize = rijTransform->InputBlockSize;


      // Retrieve the block size to write the bytes.
      int outputBlockSize = rijTransform->OutputBlockSize;

      try
      {
         // Determine if multiple blocks can be transformed.
         if ( rijTransform->CanTransformMultipleBlocks )
         {
            int numBytesRead = 0;
            while ( sourceByteLength - currentPosition >= inputBlockSize
 )
            {
               // Transform the bytes from currentPosition in the
               // sourceBytes array, writing the bytes to the targetBytes
               // array.
               numBytesRead = rijTransform->TransformBlock(
                  sourceBytes, currentPosition, inputBlockSize,
                  targetBytes, currentPosition );

               // Advance the current position in the sourceBytes array.
               currentPosition += numBytesRead;
            }

            // Transform the final block of bytes.
            array<Byte>^finalBytes = rijTransform->TransformFinalBlock(
               sourceBytes, currentPosition, sourceByteLength - currentPosition );

            // Copy the contents of the finalBytes array to the
            // targetBytes array.
            finalBytes->CopyTo( targetBytes, currentPosition );
         }
      }
      catch ( Exception^ ex ) 
      {
         Console::WriteLine( L"Caught unexpected exception:{0}", ex );
      }
      
      // Determine if the current transform can be reused.
      if (  !rijTransform->CanReuseTransform )
      {
         // Free up any used resources.
         rijTransform->Clear();
      }

      // Trim the extra bytes in the array that were not used.
      return TrimArray( targetBytes );
   }

   // Decode the specified byte array using RijndaelManagedTransform.
   static array<Byte>^ DecodeBytes( array<Byte>^sourceBytes
 )
   {
      array<Byte>^targetBytes = gcnew array<Byte>(1024);
      int currentPosition = 0;

      // Create a Rijndael decryptor from this instance to perform decryption.
      RijndaelManagedTransform^ rijTransform =
         static_cast<RijndaelManagedTransform^>(rij->CreateDecryptor());
      int inputBlockSize = rijTransform->InputBlockSize;
      int sourceByteLength = sourceBytes->Length;
      try
      {
         int numBytesRead = 0;
         while ( sourceByteLength - currentPosition >= inputBlockSize
 )
         {
            // Transform the bytes from currentposition in the
            // sourceBytes array, writing the bytes to the targetBytes
            // array.
            numBytesRead = rijTransform->TransformBlock(
               sourceBytes, currentPosition, inputBlockSize,
               targetBytes, currentPosition );

            // Advance the current position in the source array.
            currentPosition += numBytesRead;
         }
         
         // Transform the final block of bytes.
         array<Byte>^finalBytes = rijTransform->TransformFinalBlock(
            sourceBytes, currentPosition, sourceByteLength - currentPosition );

         // Copy the contents of the finalBytes array to the targetBytes
         // array.
         finalBytes->CopyTo( targetBytes, currentPosition );
      }
      catch ( Exception^ ex ) 
      {
         Console::WriteLine( L"Caught unexpected exception:{0}", ex );
      }

      // Trim the extra bytes in the array that were not used.
      return TrimArray( targetBytes );
   }

   // Resize the dimensions of the array to a size that contains only
 valid
   // bytes.
   static array<Byte>^ TrimArray( array<Byte>^targetArray
 )
   {
      IEnumerator^ enum1 = targetArray->GetEnumerator();
      int i = 0;
      while ( enum1->MoveNext() )
      {
         if ( enum1->Current->ToString()->Equals( L"0"
 ) )
         {
            break;
         }

         i++;
      }

      // Create a new array with the number of valid bytes.
      array<Byte>^returnedArray = gcnew array<Byte>(i);
      for ( int j = 0; j < i; j++ )
      {
         returnedArray[ j ] = targetArray[ j ];

      }
      return returnedArray;
   }
};

int main()
{
   Members::Main();
}
継承階層継承階層
System.Object
  System.Security.Cryptography.RijndaelManagedTransform
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RijndaelManagedTransform メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

RijndaelManagedTransform プロパティ


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

  名前 説明
パブリック プロパティ OutputBlockSize 出力ブロック サイズ取得します
参照参照

関連項目

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

その他の技術情報

暗号サービス

RijndaelManagedTransform メソッド


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

明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose アンマネージ リソース解放およびリセット関連付けられているアプリケーション定義のタスク実行します
参照参照

関連項目

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

その他の技術情報

暗号サービス

RijndaelManagedTransform メンバ

Rijndael アルゴリズム使用してデータ暗号変換実行します。このクラス継承できません。

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


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ OutputBlockSize 出力ブロック サイズ取得します
パブリック メソッドパブリック メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose アンマネージ リソース解放およびリセット関連付けられているアプリケーション定義のタスク実行します
参照参照

関連項目

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

その他の技術情報

暗号サービス



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

辞書ショートカット

すべての辞書の索引

「RijndaelManagedTransform」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS