commit
This commit is contained in:
@@ -2,6 +2,8 @@ package com.budwk.app.web.commons.auth.service;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.RsaUtils;
|
||||
import com.wf.captcha.ArithmeticCaptcha;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
@@ -11,6 +13,12 @@ import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @author wizzer@qq.com
|
||||
*/
|
||||
@@ -96,4 +104,20 @@ public class ValidateService {
|
||||
redisService.del(RedisConstant.UCENTER_SMSCODE + mobile);
|
||||
}
|
||||
|
||||
public String decryptPwd(String keyId, String password) throws Exception {
|
||||
// 从 Redis 获取私钥
|
||||
String rsaKey = RedisConstant.RSA_KEY_PREFIX + keyId;
|
||||
String privateKeyStr = redisService.get(rsaKey);
|
||||
if (privateKeyStr == null) {
|
||||
throw new BaseException("公钥已过期,请刷新登录页面");
|
||||
}
|
||||
// 删除私钥(一次性使用,防重放)
|
||||
redisService.del(rsaKey);
|
||||
// 解码私钥
|
||||
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyStr);
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
|
||||
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
|
||||
// 解密密码
|
||||
return RsaUtils.decrypt(password, privateKey);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user