26 lines
550 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|