Export (0) Print
Expand All
2 out of 9 rated this helpful - Rate this topic

Rfc2898DeriveBytes Class

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

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

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)
[<ComVisibleAttribute(true)>]
type Rfc2898DeriveBytes =  
    class 
        inherit DeriveBytes 
    end

The Rfc2898DeriveBytes type exposes the following members.

  NameDescription
Public methodRfc2898DeriveBytes(String, Byte[])Initializes a new instance of the Rfc2898DeriveBytes class using a password and salt to derive the key.
Public methodRfc2898DeriveBytes(String, Int32)Initializes a new instance of the Rfc2898DeriveBytes class using the password and salt size to derive the key.
Public methodRfc2898DeriveBytes(Byte[], Byte[], Int32)Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt, and number of iterations to derive the key.
Public methodRfc2898DeriveBytes(String, Byte[], Int32)Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt, and number of iterations to derive the key.
Public methodRfc2898DeriveBytes(String, Int32, Int32)Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt size, and number of iterations to derive the key.
Top
  NameDescription
Public propertyIterationCountGets or sets the number of iterations for the operation.
Public propertySaltGets or sets the key salt value for the operation.
Top
  NameDescription
Public methodDispose()When overridden in a derived class, releases all resources used by the current instance of the DeriveBytes class. (Inherited from DeriveBytes.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the Rfc2898DeriveBytes class and optionally releases the managed resources. (Overrides DeriveBytes.Dispose(Boolean).)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBytesReturns the pseudo-random key for this object. (Overrides DeriveBytes.GetBytes(Int32).)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodResetResets the state of the operation. (Overrides DeriveBytes.Reset().)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 Ildasm.exe (IL Disassembler), by using a hexadecimal 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.

No code example is currently available or this language may not be supported.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft. All rights reserved.