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

Glossary Item Box

Provides an interface for abstracting the password derivation routine used for password key derivation

Syntax

Visual Basic (Declaration) 
Public Interface IPasswordDerivedBytes 
C# 
public interface 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

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys