Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'System.Security.Cryptography.Rfc2898DeriveBytes': type used in a using statement must be implicitly convertible to System.IDisposable

Tags:

c#

.net

using

I have the code working in .Net framework 4.5 but when i try to code the same in .Net framework 2.0, it gives compilation error

'System.Security.Cryptography.Rfc2898DeriveBytes': type used in a using statement must be implicitly convertible to System.IDisposable

How to fix it?

CODE

[ComVisible(true)]
    public string HashPassword(string password)
    {

        byte[] salt;
        byte[] subkey;
        using (var deriveBytes = new Rfc2898DeriveBytes(password, SaltSize, PBKDF2IterCount))
        {
            salt = deriveBytes.Salt;
            subkey = deriveBytes.GetBytes(PBKDF2SubkeyLength);
        }

        var outputBytes = new byte[1 + SaltSize + PBKDF2SubkeyLength];
        //some more code goes here
        return Convert.ToBase64String(outputBytes);
    }
like image 606
Samra Avatar asked Nov 27 '25 19:11

Samra


1 Answers

Taking inspiration from André's comment, it would appear that the Dispose method wasn't introduced until .NET 4: DeriveBytes.Dispose (note: "Other Versions")

You could take a look at how the Dispose method is implemented in the current framework and consider adapating it to your project: Source Browser

like image 100
Lachlan Stewart Kidson Avatar answered Nov 30 '25 08:11

Lachlan Stewart Kidson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!