Rfc2898DeriveBytes.IterationCount プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Rfc2898DeriveBytes.IterationCount プロパティの意味・解説 

Rfc2898DeriveBytes.IterationCount プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

演算反復処理回数取得または設定します

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

Dim instance As Rfc2898DeriveBytes
Dim value As Integer

value = instance.IterationCount

instance.IterationCount = value
public int IterationCount { get;
 set; }
public:
property int IterationCount {
    int get ();
    void set (int value);
}
/** @property */
public int get_IterationCount ()

/** @property */
public void set_IterationCount (int
 value)
public function get IterationCount
 () : int

public function set IterationCount
 (value : int)

プロパティ
演算反復処理回数

例外例外
例外種類条件

ArgumentException

反復数が 1 未満です。

解説解説

反復回数は、処理を実行する回数です。このメソッド場合反復回数は、ゼロより大きい値であることが必要です。反復回数は最低でも 1000 にすることをお勧めます。

使用例使用例

Rfc2898DeriveBytes クラス使用してTripleDES クラスのまったく同じ 2 つキー作成するコード例次に示します次に、このキー使用して一部データ暗号化および復号化ます。

//The default iteration count is 1000 so the two methods use the same
 iteration count.
int myIterations = 1000;
try
{
    Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1
,myIterations);
    Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
    // Encrypt the data.
    TripleDES encAlg = TripleDES.Create();
    encAlg.Key = k1.GetBytes(16);
    MemoryStream encryptionStream = new MemoryStream();
    CryptoStream encrypt = new CryptoStream(encryptionStream,
 encAlg.CreateEncryptor(),CryptoStreamMode.Write);
    byte[] utfD1 = new System.Text.UTF8Encoding(false).GetBytes(data1);

    encrypt.Write(utfD1, 0, utfD1.Length);
    encrypt.FlushFinalBlock();
    encrypt.Close();
    byte[] edata1 = encryptionStream.ToArray();
    k1.Reset();

    // Try to decrypt, thus showing it can be round-tripped.
    TripleDES decAlg = TripleDES.Create();
    decAlg.Key = k2.GetBytes(16);
    decAlg.IV = encAlg.IV;
    MemoryStream decryptionStreamBacking = new MemoryStream();
    CryptoStream decrypt = new CryptoStream(decryptionStreamBacking,decAlg.CreateDecryptor(),
 CryptoStreamMode.Write);
    decrypt.Write(edata1, 0, edata1.Length);
    decrypt.Flush();
    decrypt.Close();
    k2.Reset();
    string data2 = new UTF8Encoding(false).GetString(decryptionStreamBacking.ToArray());

    if (!data1.Equals(data2))
    {
        Console.WriteLine("Error: The two values are not equal.");
    }
    else
    {
        Console.WriteLine("The two values are equal.");
        Console.WriteLine("k1 iterations: {0}",k1.IterationCount);
        Console.WriteLine("k2 iterations: {0}",k2.IterationCount);
    }
//The default iteration count is 1000 so the two methods use the same
 iteration count.
int myIterations = 1000;

try
{
   Rfc2898DeriveBytes ^ k1 = gcnew Rfc2898DeriveBytes( pwd1,salt1,myIterations );
   Rfc2898DeriveBytes ^ k2 = gcnew Rfc2898DeriveBytes( pwd1,salt1 );

   // Encrypt the data.
   TripleDES^ encAlg = TripleDES::Create();
   encAlg->Key = k1->GetBytes( 16 );
   MemoryStream^ encryptionStream = gcnew MemoryStream;
   CryptoStream^ encrypt = gcnew CryptoStream( encryptionStream,encAlg->CreateEncryptor(),CryptoStreamMode::Write
 );
   array<Byte>^utfD1 = (gcnew System::Text::UTF8Encoding( false
 ))->GetBytes( data1 );

   encrypt->Write( utfD1, 0, utfD1->Length );
   encrypt->FlushFinalBlock();
   encrypt->Close();
   array<Byte>^edata1 = encryptionStream->ToArray();
   k1->Reset();

   // Try to decrypt, thus showing it can be round-tripped.
   TripleDES^ decAlg = TripleDES::Create();
   decAlg->Key = k2->GetBytes( 16 );
   decAlg->IV = encAlg->IV;
   MemoryStream^ decryptionStreamBacking = gcnew MemoryStream;
   CryptoStream^ decrypt = gcnew CryptoStream( decryptionStreamBacking,decAlg->CreateDecryptor(),CryptoStreamMode::Write
 );

   decrypt->Write( edata1, 0, edata1->Length );
   decrypt->Flush();
   decrypt->Close();
   k2->Reset();

   String^ data2 = (gcnew UTF8Encoding( false ))->GetString(
 decryptionStreamBacking->ToArray() );
   if (  !data1->Equals( data2 ) )
   {
      Console::WriteLine( "Error: The two values are not equal." );
   }
   else
   {
      Console::WriteLine( "The two values are equal." );
      Console::WriteLine( "k1 iterations: {0}", k1->IterationCount );
      Console::WriteLine( "k2 iterations: {0}", k2->IterationCount );
   }
//The default iteration count is 1000 so the two methods use the
//same iteration count.
int myIterations = 1000;
try {
    Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1
,
        myIterations);
    Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
    // Encrypt the data.
    TripleDES encAlg = TripleDES.Create();
    encAlg.set_Key(k1.GetBytes(16));
    MemoryStream encryptionStream = new MemoryStream();
    CryptoStream encrypt = new CryptoStream(encryptionStream,
 
        encAlg.CreateEncryptor(), CryptoStreamMode.Write);
    ubyte utfD1[] = (new System.Text.UTF8Encoding(false)).
        GetBytes(data1);
    encrypt.Write(utfD1, 0, utfD1.get_Length());
    encrypt.FlushFinalBlock();
    encrypt.Close();
    ubyte eData1[] = encryptionStream.ToArray();
    k1.Reset();
    // Try to decrypt, thus showing it can be round-tripped.
    TripleDES decAlg = TripleDES.Create();
    decAlg.set_Key(k2.GetBytes(16));
    decAlg.set_IV(encAlg.get_IV());
    MemoryStream decryptionStreamBacking = new MemoryStream();
    CryptoStream decrypt = new CryptoStream(decryptionStreamBacking,
 
        decAlg.CreateDecryptor(), CryptoStreamMode.Write);
    decrypt.Write(eData1, 0, eData1.get_Length());
    decrypt.Flush();
    decrypt.Close();
    k2.Reset();
    String data2 = (new UTF8Encoding(false)).
        GetString(decryptionStreamBacking.ToArray());
    if (!(data1.Equals(data2))) {
        Console.WriteLine("Error: The two values are not equal.");
    }
    else {
        Console.WriteLine("The two values are equal.");
        Console.WriteLine("k1 iterations: {0}", (System.Int32)k1.
            get_IterationCount());
        Console.WriteLine("k2 iterations: {0}", (System.Int32)k2.
            get_IterationCount());
    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス



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

辞書ショートカット

すべての辞書の索引

Rfc2898DeriveBytes.IterationCount プロパティのお隣キーワード
検索ランキング

   

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



Rfc2898DeriveBytes.IterationCount プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS