From 661bd5c02857ba3a4c8348e84ef7a2926d82ed8b Mon Sep 17 00:00:00 2001 From: mashuai Date: Wed, 22 May 2024 16:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8A=A0=E5=AF=86=E6=BC=8F?= =?UTF-8?q?=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sgzb/auth/controller/TokenController.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/controller/TokenController.java b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/controller/TokenController.java index 644a0d17..a82ec65d 100644 --- a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/controller/TokenController.java +++ b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/controller/TokenController.java @@ -1,6 +1,9 @@ package com.bonus.sgzb.auth.controller; import javax.annotation.Resource; +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; import javax.servlet.http.HttpServletRequest; import com.bonus.sgzb.auth.form.*; @@ -23,6 +26,8 @@ import com.bonus.sgzb.common.security.service.TokenService; import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.system.api.model.LoginUser; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.Map; /** @@ -54,12 +59,27 @@ public class TokenController { //web端登录 @PostMapping("login") - public R login(@RequestBody LoginBody form) { + public R login(@RequestBody LoginBody form) throws Exception { + // 定义密钥 + String key = "CCNXrpassWordKey"; + byte[] encryptedBytes = Base64.getDecoder().decode(form.getPassword()); + byte[] iv = new byte[16]; + System.arraycopy(encryptedBytes, 0, iv, 0, iv.length); + + byte[] cipherText = new byte[encryptedBytes.length - iv.length]; + System.arraycopy(encryptedBytes, iv.length, cipherText, 0, cipherText.length); + + SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv)); + + byte[] decryptedBytes = cipher.doFinal(cipherText); + String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8); // 用户登录 - LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); + LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData); String uuid = form.getUuid(); String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString(); - if (StringUtils.isBlank(captcha)){ + if (StringUtils.isBlank(captcha)) { return R.fail("验证码超时,请重新刷新"); } if (form.getCode() != null && form.getCode().equals(captcha)) {