Export (0) Print
Expand All

Rfc2898DeriveBytes.Rfc2898DeriveBytes(String, Int32) Constructor

Initializes a new instance of the Rfc2898DeriveBytes class using the password and salt size to derive the key.

Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)

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

Dim instance As New Rfc2898DeriveBytes(password, saltSize)
public Rfc2898DeriveBytes (
	String password, 
	int saltSize
)
public function Rfc2898DeriveBytes (
	password : String, 
	saltSize : int
)
Not applicable.

Parameters

password

The password used to derive the key.

saltSize

The size of the random salt that you want the class to generate.

Exception typeCondition

ArgumentException

The specified salt size is smaller than 8 bytes.

ArgumentNullException

The password or salt is a null reference (Nothing in Visual Basic).

The salt size must be 8 bytes or larger.

RFC 2898 includes methods for creating a key and initialization vector (IV) from a password and salt. You can use PBKDF2, a password-based key derivation function, to derive keys using a pseudo-random function that allows keys of virtually unlimited length to be generated. The Rfc2898DeriveBytes class can be used to produce a derived key from a base key and other parameters. In a password-based key derivation function, the base key is a password and the other parameters are a salt value and an iteration count.

For more information about PBKDF2, see RFC 2898, "PKCS #5: Password-Based Cryptography Specification Version 2.0," available on the Request for Comments Web site at http://www.rfc-editor.org. See section 5.2, "PBKDF2", for complete details.

Security noteSecurity Note:

Never hard code a password within your source code. Hard-coded passwords can be retrieved from an assembly using the MSIL Disassembler (Ildasm.exe) l, a hex editor, or by simply opening up the assembly in a text editor such as Notepad.exe.

The following code example uses the Rfc2898DeriveBytes class to create two identical keys for the TripleDES class. It then encrypts and decrypts some data using the keys.

Dim k1 As New Rfc2898DeriveBytes(pwd1, salt1, myIterations)
Dim k2 As New Rfc2898DeriveBytes(pwd1, salt1)

Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,
    myIterations);
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft