23 lines
550 B
C#
Executable File
23 lines
550 B
C#
Executable File
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace MicCheck.Api.ApiKeys;
|
|
|
|
public static class ApiKeyHasher
|
|
{
|
|
public static string Hash(string key)
|
|
{
|
|
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(key));
|
|
return Convert.ToHexString(bytes).ToLowerInvariant();
|
|
}
|
|
|
|
public static string GenerateKey()
|
|
{
|
|
var bytes = RandomNumberGenerator.GetBytes(32);
|
|
return Convert.ToBase64String(bytes)
|
|
.TrimEnd('=')
|
|
.Replace('+', '-')
|
|
.Replace('/', '_');
|
|
}
|
|
}
|