add a bunch of authentication stuff

This commit is contained in:
sam 2024-05-19 17:20:45 +02:00
parent 996e59f49a
commit aca83fa1ef
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
22 changed files with 681 additions and 28 deletions

View file

@ -0,0 +1,23 @@
using System.Security.Cryptography;
namespace Foxchat.Core.Utils;
public static class CryptoUtils
{
public static bool TryFromBase64String(string b64, out byte[] bytes)
{
try
{
bytes = Convert.FromBase64String(b64);
return true;
}
catch
{
bytes = [];
return false;
}
}
public static string RandomToken(int bytes = 48) =>
Convert.ToBase64String(RandomNumberGenerator.GetBytes(bytes)).Trim('=');
}