static void Main(string[] args) { string keyDir = AppDomain.CurrentDomain.BaseDirectory; if (RSAUtils.TryGetKeyParameters(keyDir, true, out RSAParameters keyParams) == false) { Console.WriteLine("按任意键开始生产RSAKey文件。"); Console.Read(); keyParams = RSAUtils.GenerateAndSaveKey(keyDir); Console.WriteLine("RSAKey文件生存成功!"); } else { //Console.WriteLine("RSAKey文件已经存在!"); Console.WriteLine("生成jwtToken"); JwtTokenUtils jwtTokenUtils = new JwtTokenUtils(); string jwtToken = jwtTokenUtils.GenerateJwtToken("zhuqp", "", "pbirs"); Console.WriteLine(jwtToken); Console.WriteLine("验证jwtToken"); string username = jwtTokenUtils.ValidateJwtToken(jwtToken, "pbirs"); Console.WriteLine(username); Console.Read(); } }
/// <summary> /// 验证URL中的Jwt Token /// </summary> /// <param name="token"></param> /// <returns>返回Jwt Token中所携带的UserName</returns> private string CheckJwtToken(string token) { string username = null; JwtTokenUtils jwtTokenUtils = new JwtTokenUtils(); username = jwtTokenUtils.ValidateJwtToken(token, ConfigurationManager.AppSettings["Jwt_Audience_PBIRS"] ?? "pbirs"); return(username); }