In my case I was using RNGCryptoServiceProvider in .NET 5 but when I updated to .NET 6 I got the same warning. After reading about it in this issue I changed my code from this:
public string HashPassword(string plainPassword)
{
if (string.IsNullOrEmpty(plainPassword))
{
throw new ArgumentNullException(nameof(plainPassword));
}
var cryptoProvider = new RNGCryptoServiceProvider();
byte[] salt = new byte[SaltByteSize];
cryptoProvider.GetBytes(salt);
byte[] hash = GetPbkdf2Bytes(plainPassword, salt, Pbkdf2Iterations, HashByteSize);
return $"{Pbkdf2Iterations}:{Convert.ToBase64String(salt)}:{Convert.ToBase64String(hash)}";
}
To this:
public string HashPassword(string plainPassword)
{
if (string.IsNullOrEmpty(plainPassword))
{
throw new ArgumentNullException(nameof(plainPassword));
}
byte[] salt = RandomNumberGenerator.GetBytes(SaltByteSize);
byte[] hash = GetPbkdf2Bytes(plainPassword, salt, Pbkdf2Iterations, HashByteSize);
return $"{Pbkdf2Iterations}:{Convert.ToBase64String(salt)}:{Convert.ToBase64String(hash)}";
}
I know it's not exactly the same class but they are related.
SHA512 shaM = SHA512.Create()
withSystem.Security.Cryptography.SHA512
? – Ellersick