Rfc2898DeriveBytes: GetBytes |
Returns the pseudo-random key for this object.
Public Function GetBytes( ByVal cb As Long ) As Byte ( )
The Rfc2898DeriveBytes class implements PBKDF2 functionality by using a pseudorandom number generator based on HMACSHA1. The Rfc2898DeriveBytes class takes a password, a salt, and an iteration count, and then generates keys through calls to the GetBytes method. Repeated calls to this method will not generate the same key; instead, appending two calls of the GetBytes method with a cb parameter value of 20 is the equivalent of calling the GetBytes method once with a cb parameter value of 40.
Exception | Condition |
---|---|
ArgumentOutOfRangeException | cb is out of range. This parameter requires a non-negative number. |
The following example shows how to use the GetBytes method to get the key for an instance of Rfc2898DeriveBytes. This code example is part of a larger example provided for the Rfc2898DeriveBytes class.
On Error GoTo Catch Dim K1 As Rfc2898DeriveBytes Dim K2 As Rfc2898DeriveBytes Set K1 = NewRfc2898DeriveBytes(Pwd1, Salt1, MyIterations) Set K2 = NewRfc2898DeriveBytes(Pwd1, Salt1) ' Encrypt the data. Dim EncAlg As TripleDES Dim EncryptionStream As New MemoryStream Dim Encrypt As CryptoStream Dim UtfD1() As Byte Set EncAlg = TripleDES.Create() EncAlg.Key = K1.GetBytes(16) Set Encrypt = NewCryptoStream(EncryptionStream, EncAlg.CreateEncryptor(), CryptoStreamMode.WriteMode) UtfD1 = NewUTF8Encoding(False).GetBytes(Data1)