CryptoSys API Library Manual

Example: Pbe.Kdf2 

[VB6 equivalent: PBE_Kdf2]

Dim abDerivedKey() As Byte
Dim nKeyLen As Integer
Dim sPassword As String
Dim abPwdBytes() As Byte
Dim abSalt() As Byte
Dim nCount As Integer

' Convert password String to an array of Bytes
sPassword = "password"
abPwdBytes = System.Text.Encoding.Default.GetBytes(sPassword)

' Set 8-byte salt = 78 57 8E 5A 5D 63 CB 06
abSalt = New Byte() {&H78, &H57, &H8E, &H5A, &H5D, &H63, &HCB, &H6}

' Iteration count is 2048
nCount = 2048

nKeyLen = 24

' Derive PBKDF2 key using function from CryptoSys
abDerivedKey = Pbe.Kdf2(nKeyLen, abPwdBytes, abSalt, nCount)

' Convert bytes to hex and print
Console.WriteLine("Derived key = " & Cnv.ToHex(abDerivedKey))
Console.WriteLine("Correct key = BFDE6BE94DF7E11DD409BCE20A0255EC327CB936FFE93643")

See Also:
Pbe.Kdf2 Method (Int32, Byte[], Byte[], Int32)

[Contents] [Index]

[HOME]   [NEXT: Example: Pbe.Kdf2 ...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.