mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-21 07:56:09 +03:00
17 lines
490 B
C#
17 lines
490 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace JetHerald;
|
|
public static class TokenHelper
|
|
{
|
|
static readonly byte[] buf = new byte[24];
|
|
static readonly object SyncLock = new();
|
|
|
|
public static string GetToken(int length = 32)
|
|
{
|
|
var byteLength = (length + 3) / 4 * 3;
|
|
var bytes = RandomNumberGenerator.GetBytes(byteLength);
|
|
var str = Convert.ToBase64String(bytes).Substring(0, length);
|
|
return str.Replace('+', '_').Replace('/', '_');
|
|
}
|
|
}
|