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

password
salt
iterations

Glossary Item Box

Constructs the Rfc2898DeriveBytes implementation.

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal password() As Byte, _
   ByVal salt As Salt, _
   ByVal iterations As Integer _
)
C# 
public PBKDF2( 
   byte[] password,
   Salt salt,
   int iterations
)

Parameters

password
salt
iterations

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

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys