Files
YunTongJackYunTask/Reportapi/MyCode.Project.Infrastructure/Common/JwtKeyGenerator.cs
2025-07-04 09:50:02 +08:00

26 lines
550 B
C#

using System;
using System.Security.Cryptography;
namespace MyCode.Project.Infrastructure.Common
{
public class JwtKeyGenerator
{
public static string GenerateHS256Key(int keySize = 32)
{
// 生成随机字节数组
byte[] keyBytes = new byte[keySize];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetBytes(keyBytes);
}
// 转换为Base64字符串
return Convert.ToBase64String(keyBytes);
}
}
}