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

Rfc2898DeriveBytes クラス

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

HMACSHA1 に基づく擬似乱数ジェネレータ使用してパスワード ベースキー派生機能 (PBKDF2) を実装ます。

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

<ComVisibleAttribute(True)> _
Public Class Rfc2898DeriveBytes
    Inherits DeriveBytes
Dim instance As Rfc2898DeriveBytes
[ComVisibleAttribute(true)] 
public class Rfc2898DeriveBytes : DeriveBytes
[ComVisibleAttribute(true)] 
public ref class Rfc2898DeriveBytes : public
 DeriveBytes
/** @attribute ComVisibleAttribute(true) */ 
public class Rfc2898DeriveBytes extends DeriveBytes
ComVisibleAttribute(true) 
public class Rfc2898DeriveBytes extends
 DeriveBytes
解説解説

Rfc2898DeriveBytes引数として、パスワードsalt反復回数受け取り、GetBytes メソッド呼び出してキー生成します

RFC 2898 には、パスワードsalt からキーおよび初期化ベクタ (IV) を作成するためのメソッド規定されています。実質的に無制限長さキー生成できる擬似乱数関数と、パスワード ベースキー派生関数である PBKDF2使用してキー派生させることができますRfc2898DeriveBytes クラスは、基本キーおよびその他のパラメータから派生キー生成するときに使用できますパスワード ベースキー派生関数では、基本キーパスワードに、その他のパラメータsalt 値および反復回数なります

PBKDF2詳細については、RFCWeb サイト (http://www.rfc-editor.org) で、「RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0」を参照してください。特に、セクション 5.2 の「PBKDF2」を参照してください

セキュリティに関するメモセキュリティに関するメモ

パスワードソース コード内にハード コーディングすることは絶対に避けてくださいハード コーディングされたパスワードは、MSIL 逆アセンブラ (Ildasm.exe) や 16 進エディタ使用したり、アセンブリNotepad.exe などのテキスト エディタ開いたりすることによって簡単にアセンブリから取得されしまいます

使用例使用例

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

using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

public class rfc2898test
{
    // Generate a key k1 with password pwd1 and salt salt1.
    // Generate a key k2 with password pwd1 and salt salt1.
    // Encrypt data1 with key k1 using symmetric encryption, creating
 edata1.
    // Decrypt edata1 with key k2 using symmetric decryption, creating
 data2.
    // data2 should equal data1.

    private const string
 usageText = "Usage: RFC2898 <password>\nYou must specify the password
 for encryption.\n";
    public static void Main(string[]
 passwordargs)
    {
        //If no file name is specified, write usage text.
        if (passwordargs.Length == 0)
        {
            Console.WriteLine(usageText);
        }
        else
        {
            string pwd1 = passwordargs[0];
            
            byte[] salt1 = new byte[] { 0x00, 0x01, 0x02, 0x03,
 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45};
            //data1 can be a string or contents of a file.
            string data1 = "Some test data";
            //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);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: ",e);
            }

        }
    }
}
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Security::Cryptography;

// Generate a key k1 with password pwd1 and salt salt1.
// Generate a key k2 with password pwd1 and salt salt1.
// Encrypt data1 with key k1 using symmetric encryption, creating edata1.
// Decrypt edata1 with key k2 using symmetric decryption, creating data2.
// data2 should equal data1.

int main()
{
   array<String^>^passwordargs = Environment::GetCommandLineArgs();
   String^ usageText = "Usage: RFC2898 <password>\nYou must specify the
 password for encryption.\n";

   //If no file name is specified, write usage text.
   if ( passwordargs->Length == 1 )
   {
      Console::WriteLine( usageText );
   }
   else
   {
      String^ pwd1 = passwordargs[ 1 ];
      
      array<Byte>^salt1 = gcnew array<Byte>{
         0x00,0x01,0x02,0x03,0x04,0x05,0x06,0xF1,0xF0,0xEE,0x21,0x22,0x45
      };

      //data1 can be a string or contents of a file.
      String^ data1 = "Some test data";

      //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
 );
         }
      }

      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Error: ", e );
      }
   }
}
import System.*;
import System.IO.*;
import System.Text.*;
import System.Security.Cryptography.*;

public class rfc2898test
{
    // Generate a key k1 with password pwd1 and salt salt1.
    // Generate a key k2 with password pwd1 and salt salt1.
    // Encrypt data1 with key k1 using symmetric encryption, creating
 eData1.
    // Decrypt eData1 with key k2 using symmetric decryption, creating
 data2.
    // data2 should equal data1.
    private static String usageText = "Usage:
 RFC2898 <password>\n"
        + "You must specify the password for encryption.\n";

    public static void main(String[]
 passwordArgs)
    {
        //If no file name is specified, write usage text.
        if (passwordArgs.get_Length() == 0) {
            Console.WriteLine(usageText);
        }
        else {
            String pwd1 = (String)passwordArgs.get_Item(0);

            ubyte salt1[] = new ubyte[] { 0x0, 0x1, 0x2, 0x3,
 0x4, 0x5, 0x6,
                0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
            //data1 can be a string or contents of a file.
            String data1 = "Some test data";
            //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());
                }
            }           
            catch (System.Exception e) {
                Console.WriteLine("Error: ", e);
            }
        }
    } //main
} //rfc2898test
継承階層継承階層
System.Object
   System.Security.Cryptography.DeriveBytes
    System.Security.Cryptography.Rfc2898DeriveBytes
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Rfc2898DeriveBytes コンストラクタ (String, Int32)

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

キー派生させるために使用するパスワードおよび salt サイズ指定して、Rfc2898DeriveBytes クラス新しインスタンス初期化します。

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

Public Sub New ( _
    password As String, _
    saltSize As Integer _
)
Dim password As String
Dim saltSize As Integer

Dim instance As New Rfc2898DeriveBytes(password,
 saltSize)
public Rfc2898DeriveBytes (
    string password,
    int saltSize
)
public:
Rfc2898DeriveBytes (
    String^ password, 
    int saltSize
)
public Rfc2898DeriveBytes (
    String password, 
    int saltSize
)
public function Rfc2898DeriveBytes (
    password : String, 
    saltSize : int
)

パラメータ

password

キー派生させるために使用するパスワード

saltSize

クラス生成するランダム saltサイズ

例外例外
例外種類条件

ArgumentException

指定されsaltサイズが 8 バイト未満です。

ArgumentNullException

パスワードまたは saltnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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

Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
Rfc2898DeriveBytes ^ k1 = gcnew Rfc2898DeriveBytes( pwd1,salt1,myIterations );
Rfc2898DeriveBytes ^ k2 = gcnew Rfc2898DeriveBytes( pwd1,salt1 );
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,
    myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

Rfc2898DeriveBytes コンストラクタ (String, Int32, Int32)

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

キー派生させるために使用するパスワードsalt サイズ、および反復回数指定して、Rfc2898DeriveBytes クラス新しインスタンス初期化します。

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

Public Sub New ( _
    password As String, _
    saltSize As Integer, _
    iterations As Integer _
)
Dim password As String
Dim saltSize As Integer
Dim iterations As Integer

Dim instance As New Rfc2898DeriveBytes(password,
 saltSize, iterations)
public Rfc2898DeriveBytes (
    string password,
    int saltSize,
    int iterations
)
public:
Rfc2898DeriveBytes (
    String^ password, 
    int saltSize, 
    int iterations
)
public Rfc2898DeriveBytes (
    String password, 
    int saltSize, 
    int iterations
)
public function Rfc2898DeriveBytes (
    password : String, 
    saltSize : int, 
    iterations : int
)

パラメータ

password

キー派生させるために使用するパスワード

saltSize

クラス生成するランダム saltサイズ

iterations

演算反復処理回数

例外例外
例外種類条件

ArgumentException

指定されsaltサイズが 8 バイト未満であるか、反復回数1 未満です。

ArgumentNullException

パスワードまたは saltnull 参照 (Visual Basic では Nothing) です。

解説解説

saltサイズが 8 バイト以上、かつ、反復回数が 0 以上であることが必要です。反復回数は最低でも 1000 にすることをお勧めます。

RFC 2898 には、パスワードsalt からキーおよび初期化ベクタ (IV) を作成するためのメソッド規定されています。実質的に無制限長さキー生成できる擬似乱数関数と、パスワード ベースキー派生関数である PBKDF2使用してキー派生させることができますRfc2898DeriveBytes クラスは、基本キーおよびその他のパラメータから派生キー生成するときに使用できますパスワード ベースキー派生関数では、基本キーパスワードに、その他のパラメータsalt 値および反復回数なります

PBKDF2詳細については、RFCWeb サイト (http://www.rfc-editor.org) で、「RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0」を参照してください。特に、セクション 5.2 の「PBKDF2」を参照してください

セキュリティに関するメモセキュリティに関するメモ

パスワードソース コード内にハード コーディングすることは絶対に避けてくださいハード コーディングされたパスワードは、MSIL 逆アセンブラ (Ildasm.exe) や 16 進エディタ使用したり、アセンブリNotepad.exe などのテキスト エディタ開いたりすることによって簡単にアセンブリから取得されしまいます

使用例使用例

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

Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
Rfc2898DeriveBytes ^ k1 = gcnew Rfc2898DeriveBytes( pwd1,salt1,myIterations );
Rfc2898DeriveBytes ^ k2 = gcnew Rfc2898DeriveBytes( pwd1,salt1 );
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,
    myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

Rfc2898DeriveBytes コンストラクタ (Byte[], Byte[], Int32)

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

キー派生させるために使用するパスワードsalt、および反復回数指定して、Rfc2898DeriveBytes クラス新しインスタンス初期化します。

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

Public Sub New ( _
    password As Byte(), _
    salt As Byte(), _
    iterations As Integer _
)
Dim password As Byte()
Dim salt As Byte()
Dim iterations As Integer

Dim instance As New Rfc2898DeriveBytes(password,
 salt, iterations)
public Rfc2898DeriveBytes (
    byte[] password,
    byte[] salt,
    int iterations
)
public:
Rfc2898DeriveBytes (
    array<unsigned char>^ password, 
    array<unsigned char>^ salt, 
    int iterations
)
public Rfc2898DeriveBytes (
    byte[] password, 
    byte[] salt, 
    int iterations
)
public function Rfc2898DeriveBytes (
    password : byte[], 
    salt : byte[], 
    iterations : int
)

パラメータ

password

キー派生させるために使用するパスワード

salt

キー派生させるために使用するキー salt

iterations

演算反復処理回数

例外例外
例外種類条件

ArgumentException

指定されsaltサイズが 8 バイト未満であるか、反復回数1 未満です。

ArgumentNullException

パスワードまたは saltnull 参照 (Visual Basic では Nothing) です。

解説解説

saltサイズが 8 バイト以上、かつ、反復回数が 0 以上であることが必要です。反復回数は最低でも 1000 にすることをお勧めます。

RFC 2898 には、パスワードsalt からキーおよび初期化ベクタ (IV) を作成するためのメソッド規定されています。実質的に無制限長さキー生成できる擬似乱数関数と、パスワード ベースキー派生関数である PBKDF2使用してキー派生させることができますRfc2898DeriveBytes クラスは、基本キーおよびその他のパラメータから派生キー生成するときに使用できますパスワード ベースキー派生関数では、基本キーパスワードに、その他のパラメータsalt 値および反復回数なります

PBKDF2詳細については、RFCWeb サイト (http://www.rfc-editor.org) で、「RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0」を参照してください。特に、セクション 5.2 の「PBKDF2」を参照してください

セキュリティに関するメモセキュリティに関するメモ

パスワードソース コード内にハード コーディングすることは絶対に避けてくださいハード コーディングされたパスワードは、MSIL 逆アセンブラ (Ildasm.exe) や 16 進エディタ使用したり、アセンブリNotepad.exe などのテキスト エディタ開いたりすることによって簡単にアセンブリから取得されしまいます

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間

Rfc2898DeriveBytes コンストラクタ

Rfc2898DeriveBytes クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Rfc2898DeriveBytes (String, Byte[]) キー派生させるために使用するパスワードおよび salt指定してRfc2898DeriveBytes クラス新しインスタンス初期化します。
Rfc2898DeriveBytes (String, Int32) キー派生させるために使用するパスワードおよび salt サイズ指定してRfc2898DeriveBytes クラス新しインスタンス初期化します。
Rfc2898DeriveBytes (Byte[], Byte[], Int32) キー派生させるために使用するパスワードsalt、および反復回数指定してRfc2898DeriveBytes クラス新しインスタンス初期化します。
Rfc2898DeriveBytes (String, Byte[], Int32) キー派生させるために使用するパスワードsalt、および反復処理回数指定してRfc2898DeriveBytes クラス新しインスタンス初期化します。
Rfc2898DeriveBytes (String, Int32, Int32) キー派生させるために使用するパスワードsalt サイズ、および反復回数指定してRfc2898DeriveBytes クラス新しインスタンス初期化します。
参照参照

関連項目

Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間

その他の技術情報

暗号サービス

Rfc2898DeriveBytes コンストラクタ (String, Byte[], Int32)

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

キー派生させるために使用するパスワードsalt、および反復処理回数指定して、Rfc2898DeriveBytes クラス新しインスタンス初期化します。

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

Public Sub New ( _
    password As String, _
    salt As Byte(), _
    iterations As Integer _
)
Dim password As String
Dim salt As Byte()
Dim iterations As Integer

Dim instance As New Rfc2898DeriveBytes(password,
 salt, iterations)
public Rfc2898DeriveBytes (
    string password,
    byte[] salt,
    int iterations
)
public:
Rfc2898DeriveBytes (
    String^ password, 
    array<unsigned char>^ salt, 
    int iterations
)
public Rfc2898DeriveBytes (
    String password, 
    byte[] salt, 
    int iterations
)
public function Rfc2898DeriveBytes (
    password : String, 
    salt : byte[], 
    iterations : int
)

パラメータ

password

キー派生させるために使用するパスワード

salt

キー派生させるために使用するキー salt

iterations

演算反復処理回数

例外例外
例外種類条件

ArgumentException

指定されsaltサイズが 8 バイト未満であるか、反復回数1 未満です。

ArgumentNullException

パスワードまたは saltnull 参照 (Visual Basic では Nothing) です。

解説解説

saltサイズが 8 バイト以上、かつ、反復回数が 0 以上であることが必要です。反復回数は最低でも 1000 にすることをお勧めます。

RFC 2898 には、パスワードsalt からキーおよび初期化ベクタ (IV) を作成するためのメソッド規定されています。実質的に無制限長さキー生成できる擬似乱数関数と、パスワード ベースキー派生関数である PBKDF2使用してキー派生させることができますRfc2898DeriveBytes クラスは、基本キーおよびその他のパラメータから派生キー生成するときに使用できますパスワード ベースキー派生関数では、基本キーパスワードに、その他のパラメータsalt 値および反復回数なります

PBKDF2詳細については、RFCWeb サイト (http://www.rfc-editor.org) で、「RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0」を参照してください。特に、セクション 5.2 の「PBKDF2」を参照してください

セキュリティに関するメモセキュリティに関するメモ

パスワードソース コード内にハード コーディングすることは絶対に避けてくださいハード コーディングされたパスワードは、MSIL 逆アセンブラ (Ildasm.exe) や 16 進エディタ使用したり、アセンブリNotepad.exe などのテキスト エディタ開いたりすることによって簡単にアセンブリから取得されしまいます

使用例使用例

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

decrypt.Write(edata1, 0, edata1.Length);
decrypt.Flush();
decrypt.Close();
k2.Reset();
decrypt->Write( edata1, 0, edata1->Length );
decrypt->Flush();
decrypt->Close();
k2->Reset();
decrypt.Write(eData1, 0, eData1.get_Length());
decrypt.Flush();
decrypt.Close();
k2.Reset();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

Rfc2898DeriveBytes コンストラクタ (String, Byte[])

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

キー派生させるために使用するパスワードおよび salt指定して、Rfc2898DeriveBytes クラス新しインスタンス初期化します。

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

public Rfc2898DeriveBytes (
    string password,
    byte[] salt
)
public:
Rfc2898DeriveBytes (
    String^ password, 
    array<unsigned char>^ salt
)
public Rfc2898DeriveBytes (
    String password, 
    byte[] salt
)
public function Rfc2898DeriveBytes (
    password : String, 
    salt : byte[]
)

パラメータ

password

キー派生させるために使用するパスワード

salt

キー派生させるために使用するキー salt

例外例外
例外種類条件

ArgumentException

指定されsaltサイズが 8 バイト未満であるか、反復回数1 未満です。

ArgumentNullException

パスワードまたは saltnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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

Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
Rfc2898DeriveBytes ^ k1 = gcnew Rfc2898DeriveBytes( pwd1,salt1,myIterations );
Rfc2898DeriveBytes ^ k2 = gcnew Rfc2898DeriveBytes( pwd1,salt1 );
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,
    myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Rfc2898DeriveBytes クラス
Rfc2898DeriveBytes メンバ
System.Security.Cryptography 名前空間
その他の技術情報
暗号サービス

Rfc2898DeriveBytes プロパティ


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

  名前 説明
パブリック プロパティ IterationCount 演算反復処理回数取得または設定します
パブリック プロパティ Salt 演算使用するキー salt 値を取得または設定します
参照参照

関連項目

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

その他の技術情報

暗号サービス

Rfc2898DeriveBytes メソッド


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

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

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

その他の技術情報

暗号サービス

Rfc2898DeriveBytes メンバ

HMACSHA1 に基づく擬似乱数ジェネレータ使用してパスワード ベースキー派生機能 (PBKDF2) を実装ます。

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド Rfc2898DeriveBytes オーバーロードされます。 Rfc2898DeriveBytes クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ IterationCount 演算反復処理回数取得または設定します
パブリック プロパティ Salt 演算使用するキー salt 値を取得または設定します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

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

その他の技術情報

暗号サービス



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

辞書ショートカット

すべての辞書の索引

「Rfc2898DeriveBytes」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS