Visual Basic (Declaration) | |
---|---|
Public Class PBKDF2 Inherits System.Security.Cryptography.Rfc2898DeriveBytes Implements IPasswordDerivedBytes |
C# | |
---|---|
public class PBKDF2 : System.Security.Cryptography.Rfc2898DeriveBytes, IPasswordDerivedBytes |
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.NET | Copy 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 |
System.Object
System.Security.Cryptography.DeriveBytes
System.Security.Cryptography.Rfc2898DeriveBytes
CSharpTest.Net.Crypto.PBKDF2
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7