Results 1 to 4 of 4

Thread: [Help] Obsolete Code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Exclamation [Help] Obsolete Code

    Code:
        ' Use the password to generate key bytes.
        Private Sub MakeKeyAndIV(ByVal password As String, ByVal key_size_bits As Integer, ByVal block_size_bits As Integer, ByRef key As Byte(), ByRef iv As Byte())
            Dim password_derive_bytes As New PasswordDeriveBytes( _
                password, Nothing, "SHA384", 1000)
    
            key = password_derive_bytes.GetBytes(key_size_bits \ 8)
            iv = password_derive_bytes.GetBytes(block_size_bits \ 8)
        End Sub
    
    Warning	1	'Public Overrides Function GetBytes(cb As Integer) As Byte()' is obsolete: 'Rfc2898DeriveBytes replaces PasswordDeriveBytes for deriving key material from a password and is preferred in new applications.'.
    I have found the above code on generating passwords but when I converted the whole project it displays 2 warnings that the code was obsolete but when I search google I didnt found any fix for that warning.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: [Help] Obsolete Code

    You don't need to search Google. The warning message itself tells you what to do:
    Rfc2898DeriveBytes replaces PasswordDeriveBytes for deriving key material from a password and is preferred in new applications.
    You should be using the Rfc2898DeriveBytes class rather than the PasswordDeriveBytes class. The documentation can show you the usage but, while I've neevr used either myself, I think the two are used in basically the same way and it's just that the new class has an internal implementation that satisfies the latest standards.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: [Help] Obsolete Code

    I am getting an error if I change PasswordDeriveByres to Rfc2898DeriveBytes...

    vb Code:
    1. Dim password_derive_bytes As New Rfc2898DeriveBytes(password, Nothing, "SHA384", 1000)
    2.         key = password_derive_bytes.GetBytes(key_size_bits \ 8)
    3.         iv = password_derive_bytes.GetBytes(block_size_bits \ 8)

    no accessible 'New' accepts this number of arguments...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: [Help] Obsolete Code

    So have a look at the MSDN documentation for the Rfc2898DeriveBytes class and see what parameters its constructors do have. You should also be reading the documentation to see how it works. Like I said, I've never actually used it so, while I can say that they are similar from what little I've seen, I can't say whether they are the same.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width