Export (0) Print
Expand All

Rfc2898DeriveBytes Constructor (String, Int32)

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)

public Rfc2898DeriveBytes(
	string password,
	int saltSize
)

Parameters

password
Type: System.String

The password used to derive the key.

saltSize
Type: System.Int32

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

ExceptionCondition
ArgumentException

The specified salt size is smaller than 8 bytes.

ArgumentNullException

The password or salt is null.

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. 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 by using the Ildasm.exe (IL Disassembler), by using a hexadecimal editor, or by simply opening up the assembly in a text editor such as Notepad.exe.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft