This commit is contained in:
zpc 2025-09-12 11:53:21 +08:00
parent 7da6b09efc
commit 6c20bc438e

View File

@ -155,36 +155,6 @@ namespace CoreCms.Net.Auth
var signingKey = new SymmetricSecurityKey(keyByteArray);
var issuer = AppSettingsConstVars.JwtConfigIssuer;
var audience = AppSettingsConstVars.JwtConfigAudience;
// 👇 下面是你应该添加的打印代码,用于调试
Console.WriteLine("[JWT Debug] JwtConfigSecretKey 配置读取开始 =====================");
// 1. 打印密钥的长度(帮助判断是否为空或过短)
Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 长度: {symmetricKeyAsBase64.Length}");
// 2. 打印密钥的前 5 个字符(避免泄露全部密钥,但可以用于对比)
if (!string.IsNullOrEmpty(symmetricKeyAsBase64) && symmetricKeyAsBase64.Length >= 5)
{
Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 前5位: '{symmetricKeyAsBase64.Substring(0, 5)}...'");
}
else
{
Console.WriteLine($"[JWT Debug] JwtConfigSecretKey 前5位: (太短或为空)");
}
// 3. 打印密钥的 SHA256 哈希值(可用于绝对安全地对比密钥是否一致,不会泄露原文)
try
{
var sha256Hash = System.Security.Cryptography.SHA256.HashData(keyByteArray);
var hashString = BitConverter.ToString(sha256Hash).Replace("-", "").ToLower();
Console.WriteLine($"[JWT Debug] JwtConfigSecretKey SHA256 哈希值: {hashString},明文:{symmetricKeyAsBase64}");
}
catch (Exception ex)
{
Console.WriteLine($"[JWT Debug] 计算密钥哈希时出错: {ex.Message}");
}
Console.WriteLine("[JWT Debug] JwtConfigSecretKey 配置读取结束 =====================");
var signingCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256);
// 如果要数据库动态绑定,这里先留个空,后边处理器里动态赋值
@ -198,7 +168,7 @@ namespace CoreCms.Net.Auth
issuer,//发行人
audience,//听众
signingCredentials,//签名凭据
expiration: TimeSpan.FromMinutes(60 * 2)//接口的过期时间
expiration: TimeSpan.FromMinutes(60 * 24 * 5)//接口的过期时间
);
#endregion