24 lines
519 B
C#
24 lines
519 B
C#
|
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('=');
|
||
|
}
|