RijndaelManagedTransform クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(True)> _ Public NotInheritable Class RijndaelManagedTransform Implements ICryptoTransform, IDisposable
[ComVisibleAttribute(true)] public sealed class RijndaelManagedTransform : ICryptoTransform, IDisposable
[ComVisibleAttribute(true)] public ref class RijndaelManagedTransform sealed : 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.Security.Cryptography.RijndaelManagedTransform


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RijndaelManagedTransform プロパティ
RijndaelManagedTransform メソッド

名前 | 説明 | |
---|---|---|
![]() | Clear | RijndaelManagedTransform クラスによって使用されているすべてのリソースを解放します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Reset | 別の暗号化または復号化に使用できるように、RijndaelManagedTransform の内部状態をリセットします。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | TransformBlock | 入力バイト配列の指定した領域の変換を計算し、結果として得られる変換を出力バイト配列の指定した領域にコピーします。 |
![]() | TransformFinalBlock | 指定したバイト配列の指定した領域の変換を計算します。 |


RijndaelManagedTransform メンバ
Rijndael アルゴリズムを使用してデータの暗号変換を実行します。このクラスは継承できません。
RijndaelManagedTransform データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Clear | RijndaelManagedTransform クラスによって使用されているすべてのリソースを解放します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Reset | 別の暗号化または復号化に使用できるように、RijndaelManagedTransform の内部状態をリセットします。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | TransformBlock | 入力バイト配列の指定した領域の変換を計算し、結果として得られる変換を出力バイト配列の指定した領域にコピーします。 |
![]() | TransformFinalBlock | 指定したバイト配列の指定した領域の変換を計算します。 |


- RijndaelManagedTransformのページへのリンク