Rfc2898 / PBKDF2 with SHA256 as digest in c#

前端 未结 8 2308
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 10:01

I want to use Rfc2898 in c# to derive a key. I also need to use SHA256 as Digest for Rfc2898. I found the class Rfc2898DeriveBytes, but it uses SHA-1 and I don\

8条回答
  •  再見小時候
    2020-12-13 10:35

    For those who need it, .NET Framework 4.7.2 includes an overload of Rfc2898DeriveBytes that allows the hashing algorithm to be specified:

    byte[] bytes;
    using (var deriveBytes = new Rfc2898DeriveBytes(password, salt, iterations, HashAlgorithmName.SHA256))
    {
        bytes = deriveBytes.GetBytes(PBKDF2SubkeyLength);
    }
    

    The HashAlgorithmName options at the moment are:

    • MD5
    • SHA1
    • SHA256
    • SHA384
    • SHA512

提交回复
热议问题