2023-02-16 13:42:13 +00:00
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
2023-03-08 12:20:33 +00:00
|
|
|
namespace InnovEnergy.App.Backend.Utils;
|
2023-02-16 13:42:13 +00:00
|
|
|
|
2023-02-16 14:08:50 +00:00
|
|
|
public static class Crypto
|
2023-02-16 13:42:13 +00:00
|
|
|
{
|
2023-02-16 14:08:50 +00:00
|
|
|
public static String ComputeHash(Byte[] bytesToHash, Byte[] salt)
|
2023-02-16 13:42:13 +00:00
|
|
|
{
|
2023-02-21 08:58:21 +00:00
|
|
|
using var mySHA256 = SHA256.Create();
|
|
|
|
var hashValue = mySHA256.ComputeHash(bytesToHash);
|
|
|
|
// var hashValue = new Rfc2898DeriveBytes(hashValue, salt, 10000);
|
|
|
|
return Convert.ToBase64String(hashValue);
|
2023-02-16 13:42:13 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 14:08:50 +00:00
|
|
|
public static String GenerateSalt()
|
2023-02-16 13:42:13 +00:00
|
|
|
{
|
2023-02-16 14:08:50 +00:00
|
|
|
var bytes = new Byte[128 / 8];
|
|
|
|
var rng = RandomNumberGenerator.Create();
|
2023-02-16 13:42:13 +00:00
|
|
|
rng.GetBytes(bytes);
|
|
|
|
return Convert.ToBase64String(bytes);
|
|
|
|
}
|
|
|
|
}
|