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

' Pre-dimension output for derived key to required length of 24 bytes
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, HashAlgorithm)

[Contents] [Index]

[PREV: Example: Tdea.Unpad ...]   [Contents]   [Index]   
   [NEXT: Example: Pbe.Kdf2 ...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-20T13:01:10Z.