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

SymmetricAlgorithm クラス

対称アルゴリズムすべての実装継承する必要がある抽象基本クラス表します

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

<ComVisibleAttribute(True)> _
Public MustInherit Class
 SymmetricAlgorithm
    Implements IDisposable
Dim instance As SymmetricAlgorithm
[ComVisibleAttribute(true)] 
public abstract class SymmetricAlgorithm :
 IDisposable
[ComVisibleAttribute(true)] 
public ref class SymmetricAlgorithm abstract
 : IDisposable
/** @attribute ComVisibleAttribute(true) */ 
public abstract class SymmetricAlgorithm implements
 IDisposable
ComVisibleAttribute(true) 
public abstract 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.Object
  System.Security.Cryptography.SymmetricAlgorithm
     System.Security.Cryptography.DES
     System.Security.Cryptography.RC2
     System.Security.Cryptography.Rijndael
     System.Security.Cryptography.TripleDES
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SymmetricAlgorithm コンストラクタ

SymmetricAlgorithm クラス新しインスタンス初期化します。

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

Dim instance As New SymmetricAlgorithm
protected SymmetricAlgorithm ()
protected:
SymmetricAlgorithm ()
protected SymmetricAlgorithm ()
protected function SymmetricAlgorithm ()
例外例外
例外種類条件

CryptographicException

対称アルゴリズム派生クラス実装が有効ではありません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SymmetricAlgorithm クラス
SymmetricAlgorithm メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

SymmetricAlgorithm フィールド


SymmetricAlgorithm プロパティ


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

参照参照

関連項目

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

その他の技術情報

暗号サービス

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 指定されキー サイズが、現在のアルゴリズムに対して有効かどうか判断します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose SymmetricAlgorithm によって使用されているアンマネージ リソース解放しオプションマネージ リソース解放します。
参照参照

関連項目

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

その他の技術情報

暗号サービス

SymmetricAlgorithm メンバ

対称アルゴリズムすべての実装継承する必要がある抽象基本クラス表します

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


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド 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 指定されキー サイズが、現在のアルゴリズムに対して有効かどうか判断します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose SymmetricAlgorithm によって使用されているアンマネージ リソース解放しオプションマネージ リソース解放します。
参照参照

関連項目

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

その他の技術情報

暗号サービス



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

辞書ショートカット

すべての辞書の索引

「SymmetricAlgorithm」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS