Foxchat.NET/Foxchat.Core/Utils/CryptoUtils.cs

24 lines
519 B
C#
Raw Normal View History

2024-05-19 17:20:45 +02:00
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('=');
}