added salt to password, it's edible now

This commit is contained in:
Kim 2023-02-16 14:42:13 +01:00
parent d3be39d265
commit 9d19c0fca9
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
using System.Security.Cryptography;
namespace Backend.Utils;
public class Crypto
{
public String ComputeHash(Byte[] bytesToHash, Byte[] salt)
{
var byteResult = new Rfc2898DeriveBytes(bytesToHash, salt, 10000);
return Convert.ToBase64String(byteResult.GetBytes(24));
}
public string GenerateSalt()
{
var bytes = new byte[128 / 8];
var rng = new RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return Convert.ToBase64String(bytes);
}
}