20 lines
558 B
C#
20 lines
558 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace MxGateway.Server.Security.Authentication;
|
|
|
|
/// <summary>Generates cryptographically secure API key secrets.</summary>
|
|
public static class ApiKeySecretGenerator
|
|
{
|
|
/// <summary>Generates a new random API key secret string.</summary>
|
|
public static string Generate()
|
|
{
|
|
Span<byte> bytes = stackalloc byte[32];
|
|
RandomNumberGenerator.Fill(bytes);
|
|
|
|
return Convert.ToBase64String(bytes)
|
|
.TrimEnd('=')
|
|
.Replace('+', '-')
|
|
.Replace('/', '_');
|
|
}
|
|
}
|