Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot specify 4 arguments (hash algorithm name) for Rfc2898DeriveBytes

According to the docs here, I should be able to create Rfc2898DeriveBytes with a custom hash algorithm (SHA256 in my case):

public Rfc2898DeriveBytes (byte[] password, byte[] salt, int iterations, System.Security.Cryptography.HashAlgorithmName hashAlgorithm);

I have created a .NET Standard 2.0 class library with the following:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

My Class

private static byte[] Pbkdf2(string data)
{
    // ...
    using(var pbkdf2 = new Rfc2898DeriveBytes(null, null, 50000, HashAlgorithmName.SHA256))
    {
        return pbkdf2.GetBytes(32);
    }
}

I get the following error:

'Rfc2898DeriveBytes' does not contain a constructor that takes 4 arguments

Why can I not add a hash algorithm to the constructor of Rfc2898DeriveBytes?

like image 322
kspearrin Avatar asked Aug 12 '26 19:08

kspearrin


1 Answers

The link you posted is for .NET Framework, not .NET Standard. The documentation for.NET Standard is here. In .NET Standard there is no constructor with 4 parameters.

like image 76
Ivan Vargas Avatar answered Aug 14 '26 10:08

Ivan Vargas



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!