Rfc2898DeriveBytes Constructor (String, array<Byte[])
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Initializes a new instance of the Rfc2898DeriveBytes class using a password and salt to derive the key.
Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
password As String, _
salt As Byte() _
)
public Rfc2898DeriveBytes(
string password,
byte[] salt
)
Parameters
- password
Type: System.String
The password used to derive the key.
- salt
Type: array<System.Byte[]
The key salt used to derive the key.
Exceptions
Exception | Condition |
---|---|
ArgumentException | The specified salt size is smaller than 8 bytes or the iteration count is less than 1. |
ArgumentNullException | The password or salt is nulla null reference (Nothing in Visual Basic). |
Remarks
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 Comment Web site. See section 5.2, "PBKDF2," for complete details.
Security Note: |
---|
Never hard-code a password within your source code. Hard-coded passwords can be retrieved from an assembly by using the Microsoft Intermediate Language Disassembler (Ildasm.exe), by using a hexadecimal editor, or by simply opening up the assembly in a text editor such as Notepad.exe. |
Examples
The following example demonstrates how to use the Rfc2898DeriveBytes constructor to encrypt an isolated storage file. This code example is part of a larger example provided for the AesManaged class.
AesManaged#3
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also