From f767752aa48256db3cd69d81d8c3f402cd80cf1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E6=B0=B8=E8=BE=BE?= Date: Mon, 12 Jun 2023 09:42:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96RSA=E5=AF=86=E9=92=A5=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/System/SysLoginController.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 + }); + } } }