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

<ComVisibleAttribute(True)> _ Public MustInherit Class SymmetricAlgorithm Implements IDisposable

このクラスは SymmetricAlgorithm クラスから派生しており、CBC (Cipher Block Chaining) と呼ばれるチェーン モードが使用されます。このモードでデータの暗号変換を実行するには、キー (Key) と初期化ベクタ (IV) が必要になります。SymmetricAlgorithm クラスのいずれかを使用して暗号化されたデータを復号化するには、Key プロパティと IV プロパティを、暗号化に使用された値と同じ値に設定する必要があります。対称アルゴリズムを使用する場合には、送信者と受信者以外に共有キーを知られないようにする必要があります。
RijndaelManaged、DESCryptoServiceProvider、RC2CryptoServiceProvider、および TripleDESCryptoServiceProvider は、対称アルゴリズムの実装です。
セキュリティの観点から考えると、派生クラスを使用する場合はオブジェクトの使用後にガベージ コレクションを実行するだけでは不十分です。オブジェクトに対して明示的に Clear メソッドを呼び出し、オブジェクト内の重要情報をすべて 0 にした後で解放する必要があります。ガベージ コレクションでは、収集されたオブジェクトのコンテンツをすべて 0 にするのではなく、単純にメモリを再割り当て可能としてマークするだけです。したがって、ガベージ コレクションの対象となったオブジェクトのデータが、未割り当てメモリのメモリ ヒープ内に残る場合があります。暗号化オブジェクトの場合、このデータにキー データや平文ブロックなどの機密情報が含まれている可能性があります。
.NET Framework では、重要情報を格納するすべての暗号化クラスに Clear メソッドが実装されています。Clear メソッドを呼び出すと、オブジェクト内の重要情報がすべて 0 で上書きされた後、オブジェクトが解放されます。これにより、オブジェクトに安全にガベージ コレクションを実行できます。オブジェクトが 0 で上書きされて解放されたら、disposing パラメータを True に設定して Dispose メソッドを呼び出し、オブジェクトに関連付けられているマネージ リソースとアンマネージ リソースをすべて破棄する必要があります。
継承時の注意 SymmetricAlgorithm クラスから継承する場合、CreateDecryptor、CreateEncryptor、GenerateIV、GenerateKey の各メンバをオーバーライドする必要があります。
指定した Key プロパティと初期化ベクタ (IV) で RijndaelManaged クラスを使用して、inName で指定されたファイルを暗号化し、暗号化の結果を outName で指定したファイルに出力するコード例を次に示します。このメソッドに対する desKey パラメータおよび desIV パラメータは、8 バイト配列です。このコード例を実行するには、高度暗号化パックがインストールされている必要があります。
Private Shared Sub EncryptData(inName As String, outName As String, _ rijnKey() As Byte, rijnIV() As Byte) 'Create the file streams to handle the input and output files. Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read) Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _ FileAccess.Write) fout.SetLength(0) 'Create variables to help with read and write. Dim bin(100) As Byte 'This is intermediate storage for the encryption. Dim rdlen As Long = 0 'This is the total number of bytes written. Dim totlen As Long = fin.Length 'Total length of the input file. Dim len As Integer 'This is the number of bytes to be written at a time. 'Creates the default implementation, which is RijndaelManaged. Dim rijn As SymmetricAlgorithm = SymmetricAlgorithm.Create() Dim encStream As New CryptoStream(fout, _ rijn.CreateEncryptor(rijnKey, rijnIV), CryptoStreamMode.Write) Console.WriteLine("Encrypting...") 'Read from the input file, then encrypt and write to the output file. While rdlen < totlen len = fin.Read(bin, 0, 100) encStream.Write(bin, 0, len) rdlen = Convert.ToInt32(rdlen + len) Console.WriteLine("{0} bytes processed", rdlen) End While encStream.Close() fout.Close() fin.Close() End Sub
private static void EncryptData(String inName, String outName, byte[] rijnKey, byte[] rijnIV) { //Create the file streams to handle the input and output files. FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream(outName, FileMode.OpenOrCreate , FileAccess.Write); fout.SetLength(0); //Create variables to help with read and write. byte[] bin = new byte[100]; //This is intermediate storage for the encryption. long rdlen = 0; //This is the total number of bytes written. long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); //Creates the default implementation, which is RijndaelManaged. CryptoStream encStream = new CryptoStream(fout, rijn.CreateEncryptor(rijnKey, rijnIV), CryptoStreamMode.Write); Console.WriteLine("Encrypting..."); //Read from the input file, then encrypt and write to the output file. while(rdlen < totlen) { len = fin.Read(bin, 0, 100); encStream.Write(bin, 0, len); rdlen = rdlen + len; Console.WriteLine("{0} bytes processed", rdlen); } encStream.Close(); fout.Close(); fin.Close(); }
void EncryptData( String^ inName, String^ outName, array<Byte>^rijnKey, array<Byte>^rijnIV ) { //Create the file streams to handle the input and output files. FileStream^ fin = gcnew FileStream( inName,FileMode::Open,FileAccess::Read ); FileStream^ fout = gcnew FileStream( outName,FileMode::OpenOrCreate,FileAccess::Write ); fout->SetLength( 0 ); //Create variables to help with read and write. array<Byte>^bin = gcnew array<Byte>(100); long rdlen = 0; //This is the total number of bytes written. long totlen = (long)fin->Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. SymmetricAlgorithm^ rijn = SymmetricAlgorithm::Create(); //Creates the default implementation, which is RijndaelManaged. CryptoStream^ encStream = gcnew CryptoStream( fout,rijn->CreateEncryptor( rijnKey, rijnIV ),CryptoStreamMode::Write ); Console::WriteLine( "Encrypting..." ); //Read from the input file, then encrypt and write to the output file. while ( rdlen < totlen ) { len = fin->Read( bin, 0, 100 ); encStream->Write( bin, 0, len ); rdlen = rdlen + len; Console::WriteLine( "{0} bytes processed", rdlen ); } encStream->Close(); fout->Close(); fin->Close(); }
private static void EncryptData(String inName, String outName, ubyte rijnKey[], ubyte rijnIV[]) { //Create the file streams to handle the input and output files. FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream(outName, FileMode.OpenOrCreate , FileAccess.Write); fout.SetLength(0); //Create variables to help with read and write. //Following is intermediate storage for the encryption. ubyte bin[] = new ubyte[100]; //Following is the total number of bytes written. long rdlen = 0; //Following is the total length of the input file. long totlen = fin.get_Length(); //Following is the number of bytes to be written at a time. int len; //Create the default implementation, which is RijndaelManaged. SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); CryptoStream encStream = new CryptoStream(fout, rijn.CreateEncryptor(rijnKey, rijnIV), CryptoStreamMode.Write); Console.WriteLine("Encrypting..."); //Read from the input file, then encrypt and write to the output file. while (rdlen < totlen) { len = fin.Read(bin, 0, 100); encStream.Write(bin, 0, len); rdlen = rdlen + len; Console.WriteLine("{0} bytes processed", (System.Int64)rdlen); } encStream.Close(); fout.Close(); fin.Close(); } //EncryptData

System.Security.Cryptography.SymmetricAlgorithm
System.Security.Cryptography.DES
System.Security.Cryptography.RC2
System.Security.Cryptography.Rijndael
System.Security.Cryptography.TripleDES


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SymmetricAlgorithm コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)




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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SymmetricAlgorithm フィールド

名前 | 説明 | |
---|---|---|
![]() | BlockSizeValue | 暗号操作のブロック サイズをビット単位で表します。 |
![]() | FeedbackSizeValue | 暗号操作のフィードバック サイズをビット単位で表します。 |
![]() | IVValue | 対称アルゴリズムで使用する初期化ベクタ (IV) を表します。 |
![]() | KeySizeValue | 対称アルゴリズムで使用する共有キーのサイズをビット単位で表します。 |
![]() | KeyValue | 対称アルゴリズムの共有キーを表します。 |
![]() | LegalBlockSizesValue | 対称アルゴリズムでサポートされているブロック サイズを指定します。 |
![]() | LegalKeySizesValue | 対称アルゴリズムでサポートされているキー サイズを指定します。 |
![]() | ModeValue | 対称アルゴリズムで使用する暗号モードを表します。 |
![]() | PaddingValue | 対称アルゴリズムで使用する埋め込みモードを表します。 |

SymmetricAlgorithm プロパティ
SymmetricAlgorithm メソッド

名前 | 説明 | |
---|---|---|
![]() | Clear | SymmetricAlgorithm クラスによって使用されているすべてのリソースを解放します。 |
![]() | Create | オーバーロードされます。 対称アルゴリズムを実行するために使用する暗号オブジェクトを作成します。 |
![]() | CreateDecryptor | オーバーロードされます。 対称復号化オブジェクトを作成します。 |
![]() | CreateEncryptor | オーバーロードされます。 対称暗号化オブジェクトを作成します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GenerateIV | 派生クラスでオーバーライドされると、アルゴリズムで使用するランダムな初期化ベクタ (IV) を生成します。 |
![]() | GenerateKey | 派生クラスでオーバーライドされると、アルゴリズムで使用するランダム キー (Key) を生成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | ValidKeySize | 指定されたキー サイズが、現在のアルゴリズムに対して有効かどうかを判断します。 |

名前 | 説明 | |
---|---|---|
![]() | Dispose | SymmetricAlgorithm によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.IDisposable.Dispose | SymmetricAlgorithm によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |

SymmetricAlgorithm メンバ
対称アルゴリズムのすべての実装が継承する必要がある、抽象基本クラスを表します。
SymmetricAlgorithm データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | BlockSizeValue | 暗号操作のブロック サイズをビット単位で表します。 |
![]() | FeedbackSizeValue | 暗号操作のフィードバック サイズをビット単位で表します。 |
![]() | IVValue | 対称アルゴリズムで使用する初期化ベクタ (IV) を表します。 |
![]() | KeySizeValue | 対称アルゴリズムで使用する共有キーのサイズをビット単位で表します。 |
![]() | KeyValue | 対称アルゴリズムの共有キーを表します。 |
![]() | LegalBlockSizesValue | 対称アルゴリズムでサポートされているブロック サイズを指定します。 |
![]() | LegalKeySizesValue | 対称アルゴリズムでサポートされているキー サイズを指定します。 |
![]() | ModeValue | 対称アルゴリズムで使用する暗号モードを表します。 |
![]() | PaddingValue | 対称アルゴリズムで使用する埋め込みモードを表します。 |


名前 | 説明 | |
---|---|---|
![]() | Clear | SymmetricAlgorithm クラスによって使用されているすべてのリソースを解放します。 |
![]() | Create | オーバーロードされます。 対称アルゴリズムを実行するために使用する暗号オブジェクトを作成します。 |
![]() | CreateDecryptor | オーバーロードされます。 対称復号化オブジェクトを作成します。 |
![]() | CreateEncryptor | オーバーロードされます。 対称暗号化オブジェクトを作成します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GenerateIV | 派生クラスでオーバーライドされると、アルゴリズムで使用するランダムな初期化ベクタ (IV) を生成します。 |
![]() | GenerateKey | 派生クラスでオーバーライドされると、アルゴリズムで使用するランダム キー (Key) を生成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | ValidKeySize | 指定されたキー サイズが、現在のアルゴリズムに対して有効かどうかを判断します。 |

名前 | 説明 | |
---|---|---|
![]() | Dispose | SymmetricAlgorithm によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.IDisposable.Dispose | SymmetricAlgorithm によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |

Weblioに収録されているすべての辞書からSymmetricAlgorithmを検索する場合は、下記のリンクをクリックしてください。

- SymmetricAlgorithmのページへのリンク