Rfc2898DeriveBytes Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Implements password-based key derivation functionality, PBKDF2, by using a pseudo-random number generator based on HMACSHA1.

Inheritance Hierarchy

System.Object
  System.Security.Cryptography.DeriveBytes
    System.Security.Cryptography.Rfc2898DeriveBytes

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Class Rfc2898DeriveBytes _
    Inherits DeriveBytes
[ComVisibleAttribute(true)]
public class Rfc2898DeriveBytes : DeriveBytes

The Rfc2898DeriveBytes type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone Rfc2898DeriveBytes(String, array<Byte[]) Initializes a new instance of the Rfc2898DeriveBytes class using a password and salt to derive the key.
Public methodSupported by Silverlight for Windows Phone Rfc2898DeriveBytes(array<Byte[], array<Byte[], Int32) Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt, and number of iterations to derive the key.
Public methodSupported by Silverlight for Windows Phone Rfc2898DeriveBytes(String, array<Byte[], Int32) Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt, and number of iterations to derive the key.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone IterationCount Gets or sets the number of iterations for the operation.
Public propertySupported by Silverlight for Windows Phone Salt Gets or sets the key salt value for the operation.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetBytes Returns a pseudo-random key from a password, salt and iteration count. (Overrides DeriveBytes.GetBytes(Int32).)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone Reset Resets the state of the operation. (Overrides DeriveBytes.Reset().)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

Rfc2898DeriveBytes takes a password, a salt, and an iteration count, and then generates keys through calls to the GetBytes method.

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 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 class 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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.