|
|
|
@ -7,11 +7,10 @@ import com.zdxt.enforcementcode.common.commonenum.PlatformTypeEnums; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.dromara.common.core.domain.R; |
|
|
|
import org.dromara.common.core.domain.model.LoginUser; |
|
|
|
import org.dromara.common.encrypt.utils.EncryptUtils; |
|
|
|
import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import javax.crypto.Cipher; |
|
|
|
import javax.crypto.spec.IvParameterSpec; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Base64; |
|
|
|
import java.util.Map; |
|
|
|
@ -39,6 +38,9 @@ public abstract class LoginController { |
|
|
|
*/ |
|
|
|
protected static final long APP_TOKEN_ACTIVE_TIMEOUT = 86400; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private com.zdxt.enforcementcode.common.config.RuoYiConfig ruoYiConfig; |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验登录参数非空 |
|
|
|
* |
|
|
|
@ -61,7 +63,7 @@ public abstract class LoginController { |
|
|
|
*/ |
|
|
|
protected String decryptPassword(String secretKey) { |
|
|
|
try { |
|
|
|
return decryptByAes(secretKey); |
|
|
|
return decryptByRsa(secretKey); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("密码解密失败", e); |
|
|
|
return null; |
|
|
|
@ -109,27 +111,11 @@ public abstract class LoginController { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* AES/CBC/ZeroPadding 解密(与前端CryptoJS对应) |
|
|
|
* 前端使用 CryptoJS.pad.ZeroPadding,Java中用NoPadding后手动去除尾部0字节 |
|
|
|
* RSA 私钥解密前端传来的密码 |
|
|
|
* 前端使用 RSA 公钥加密,后端使用私钥解密 |
|
|
|
*/ |
|
|
|
private String decryptByAes(String encryptedBase64) throws Exception { |
|
|
|
byte[] keyBytes = AES_KEY.getBytes(StandardCharsets.UTF_8); |
|
|
|
byte[] ivBytes = AES_KEY.getBytes(StandardCharsets.UTF_8); |
|
|
|
|
|
|
|
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); |
|
|
|
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); |
|
|
|
|
|
|
|
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); |
|
|
|
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); |
|
|
|
|
|
|
|
byte[] encrypted = Base64.getDecoder().decode(encryptedBase64); |
|
|
|
byte[] decrypted = cipher.doFinal(encrypted); |
|
|
|
|
|
|
|
// 去除ZeroPadding尾部的0字节
|
|
|
|
int len = decrypted.length; |
|
|
|
while (len > 0 && decrypted[len - 1] == 0) { |
|
|
|
len--; |
|
|
|
} |
|
|
|
return new String(decrypted, 0, len, StandardCharsets.UTF_8); |
|
|
|
private String decryptByRsa(String encryptedBase64) throws Exception { |
|
|
|
String privateKey = ruoYiConfig.getPrivateKey(); |
|
|
|
return EncryptUtils.decryptByRsa(encryptedBase64, privateKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|