7

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?

2
  • 1
    For what it's worth this API with HashAlgorithmName will be part of .NET Standard 2.1. apisof.net/catalog/… Commented Nov 8, 2018 at 5:08
  • 6
    I'm unable to use .NET Standard 2.1 as I need the library to be shared between .NET Framework 4.8 and .NET Core. Any advice? 3rd Party Library? Commented Dec 18, 2020 at 20:31

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I guess I missed that little version switcher select list at the top. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.