无法为 Rfc2898DeriveBytes 指定 4 个参数(哈希算法名称)

ksp*_*rin 6 c# .net-core .net-standard

根据此处的文档,我应该能够Rfc2898DeriveBytes使用自定义哈希算法(在我的例子中为 SHA256)创建:

public Rfc2898DeriveBytes (byte[] password, byte[] salt, int iterations, System.Security.Cryptography.HashAlgorithmName hashAlgorithm);
Run Code Online (Sandbox Code Playgroud)

我创建了一个 .NET Standard 2.0 类库,其中包含以下内容:

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

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

</Project>
Run Code Online (Sandbox Code Playgroud)

我的课

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

我收到以下错误:

“Rfc2898DeriveBytes”不包含带有 4 个参数的构造函数

为什么我不能将哈希算法添加到 的构造函数中Rfc2898DeriveBytes

Iva*_*gas 3

您发布的链接适用于 .NET Framework,而不是 .NET Standard。.NET Standard 的文档位于此处。在 .NET Standard 中,没有带有 4 个参数的构造函数。