Innovenergy_trunk/csharp/app/Backend/Utils/Crypto.cs

20 lines
535 B
C#
Raw Normal View History

using System.Security.Cryptography;
namespace Backend.Utils;
2023-02-16 14:08:50 +00:00
public static class Crypto
{
2023-02-16 14:08:50 +00:00
public static String ComputeHash(Byte[] bytesToHash, Byte[] salt)
{
var byteResult = new Rfc2898DeriveBytes(bytesToHash, salt, 10000);
return Convert.ToBase64String(byteResult.GetBytes(24));
}
2023-02-16 14:08:50 +00:00
public static String GenerateSalt()
{
2023-02-16 14:08:50 +00:00
var bytes = new Byte[128 / 8];
var rng = RandomNumberGenerator.Create();
rng.GetBytes(bytes);
return Convert.ToBase64String(bytes);
}
}