CSharpTest.Net
PBKDF2 Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace : PBKDF2 Class

Glossary Item Box

Provided an implementation of Rfc2898DeriveBytes accessable via the IPasswordDerivedBytes interface. One primary difference in GetBytes() ensures that the number of bytes generated are always rounded to hash size, thus GetBytes(4) + GetBytes(4) != GetBytes(8)

Syntax

Visual Basic (Declaration) 
Public Class PBKDF2 
   Inherits System.Security.Cryptography.Rfc2898DeriveBytes
   Implements IPasswordDerivedBytes 

Example

Library/Library.Test/TestPassword.cs

C#Copy Code
int iter = 100;
Salt salt = new Salt();
byte[] passbytes = Password.Encoding.GetBytes(TEST_PASSWORD);
IPasswordDerivedBytes[] types = new IPasswordDerivedBytes[] {
    new PBKDF2(passbytes, salt, iter),
    new HashDerivedBytes<HMACMD5>(passbytes, salt, iter),
    new HashDerivedBytes<HMACSHA1>(passbytes, salt, iter),
    new HashDerivedBytes<HMACSHA256>(passbytes, salt, iter),
    new HashDerivedBytes<HMACSHA384>(passbytes, salt, iter),
    new HashDerivedBytes<HMACSHA512>(passbytes, salt, iter),
};

foreach (IPasswordDerivedBytes db in types)
{
    byte[] key;
    
    Stopwatch w = new Stopwatch();
    w.Start();
    for (int i = 0; i < 100; i++)
        key = new PasswordKey(db, salt).CreateKey().Key;
    w.Stop();

    Console.Error.WriteLine("{0,10}  {1}", w.ElapsedMilliseconds, db.GetType().Name);
}
VB.NETCopy Code
Dim iter As Integer = 100
Dim salt As New Salt()
Dim passbytes As Byte() = Password.Encoding.GetBytes(TEST_PASSWORD)
Dim types As IPasswordDerivedBytes() = New IPasswordDerivedBytes() {New PBKDF2(passbytes, salt, iter), New HashDerivedBytes(Of HMACMD5)(passbytes, salt, iter), New HashDerivedBytes(Of HMACSHA1)(passbytes, salt, iter), New HashDerivedBytes(Of HMACSHA256)(passbytes, salt, iter), New HashDerivedBytes(Of HMACSHA384)(passbytes, salt, iter), New HashDerivedBytes(Of HMACSHA512)(passbytes, salt, iter)}

For Each db As IPasswordDerivedBytes In types
    Dim key As Byte()

    Dim w As New Stopwatch()
    w.Start()
    Dim i As Integer = 0
    While i < 100
        key = New PasswordKey(db, salt).CreateKey().Key
        System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
    End While
    w.[Stop]()

    Console.[Error].WriteLine("{0,10}  {1}", w.ElapsedMilliseconds, db.[GetType]().Name)
Next

Inheritance Hierarchy

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys