diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index bb8c8d4..0850f9c 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; +using NETCore.Encrypt; using UAParser; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; @@ -58,7 +59,9 @@ namespace ZR.Admin.WebApi.Controllers.System roleService = sysRoleService; this.jwtSettings = jwtSettings.Value; } - + + // RSA私钥 + private static string _privateKey; /// /// 登录 @@ -77,7 +80,8 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误"); } - + // RSA解密 + loginBody.Password = EncryptProvider.RSADecryptWithPem(_privateKey, loginBody.Password); var user = sysLoginService.Login(loginBody, RecordLogInfo(httpContextAccessor.HttpContext)); List roles = roleService.SelectUserRoleListByUserId(user.UserId); @@ -210,5 +214,19 @@ namespace ZR.Admin.WebApi.Controllers.System } return ToResponse(ResultCode.CUSTOM_ERROR, "注册失败,请联系管理员"); } + + /// + /// 获取RSA公钥和密钥 + /// + /// + [HttpGet("getRsaKey")] + public IActionResult GetRsaKey() + { + var (publicPem, privatePem) = EncryptProvider.RSAToPem(true); + _privateKey = privatePem; + return SUCCESS(new { + PublicKey = publicPem + }); + } } }