Commit 67ae1d61 authored by ma's avatar ma

采用rsa加密

parent c6481e69
......@@ -15,6 +15,7 @@
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<acc.secret.version>1.0.4</acc.secret.version>
</properties>
<dependencies>
......@@ -144,6 +145,12 @@
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.acc</groupId>
<artifactId>secret</artifactId>
<version>${acc.secret.version}</version>
</dependency>
<!--邮件-->
<dependency>
<groupId>org.springframework.boot</groupId>
......
package iot.sixiang.license.controller;
import com.acc.secret.util.RSAUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -47,8 +48,10 @@ public class LoginController {
@Value("${spring.mail.to}")
private String account;
@Value("${other.md5.salt}")
private String salt;
@Value("${rsa.private_key}")
private String PRIVATE_KRY;
@Value("${rsa.public_key}")
private String PUBLIC_KEY;
private static final String USER_NAME = "root";
/**
......@@ -68,9 +71,9 @@ public class LoginController {
}
User user = userMapper.getUserByUserName(USER_NAME);
String name = USER_NAME;
String psw = user.getPassword();
String pwd = user.getPassword();
LoginUser dbUser = new LoginUser(String.valueOf(user.getUserId()), user.getUserName(), user.getPassword());
if (DigestUtils.md5DigestAsHex((salt + name + salt).getBytes()).equals(userName) && psw.equals(password)) {
if (name.equals(userName) && RSAUtil.getDecryptString(password, PRIVATE_KRY).equals(pwd)) {
// 登录错误次数
Integer errCnt = UserUtils.getErrCnt(userName);
Date countFreezeDate = UserUtils.getCountFreezeDate(userName);
......@@ -84,6 +87,7 @@ public class LoginController {
LoginVo loginVo = new LoginVo();
loginVo.setAuthorization(token);
loginVo.setUpdateTime(user.getUpdateTime());
loginVo.setPubKey(PUBLIC_KEY);
UserUtils.setToken(dbUser.getUserId(), token);
UserUtils.setTokenExp(dbUser.getUserId(), JwtUtil.getTokenExp());
UserUtils.removeErrCnt(userName);
......
package iot.sixiang.license.controller;
import com.acc.secret.util.RSAUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
......@@ -45,8 +46,8 @@ public class UserController {
@Autowired
private UserService userService;
@Value("${other.md5.salt}")
private String salt;
@Value("${rsa.private_key}")
private String PRIVATE_KRY;
@InitBinder
public void initBinder(WebDataBinder binder) {
......@@ -135,6 +136,8 @@ public class UserController {
} else {
return BaseResult.failed();
}
oldPassWord = RSAUtil.getDecryptString(oldPassWord, PRIVATE_KRY);
newPassWord = RSAUtil.getDecryptString(newPassWord, PRIVATE_KRY);
if (oldPassWord.equals(user.getPassword())) {
user.setPassword(newPassWord);
boolean b = userService.updateUser(user);
......
......@@ -14,6 +14,9 @@ public class LoginVo {
@ApiModelProperty("token")
private String authorization;
@ApiModelProperty("pubKey")
private String pubKey;
@ApiModelProperty("更新时间")
private Date updateTime;
}
......@@ -32,5 +32,12 @@ server:
cros:
# 需要设置访问白名单
cros_allowed_origins: http://192.168.1.88:8080, http://localhost:8868
cros_allowed_origins: http://192.168.1.88:8080, http://localhost:8868, http://localhost:8080
cros_allowed_method: GET,POST
other:
md5:
salt: PI7dBYlEfeP8IZ6vogqFL1U5pVnyCuNAGja3lsREx4M9r0SX
rsa:
public_key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA18W2H1hO98dUWf1PNKNWTWmxCyvvy0NOR7iSvp76J0LdzyMJxs8WHVAmRfSGOb9SvpDZhBVx11bhTBqkl1qMzJWzn+F2ZtTCH2nXZcJHwSfLuGqin5FRBYW1WrFkqwg+R80aOuRSrbo0k1bZg3JPkkCxISHieEZPjSV5a4r7+Xopj0a9Dnh3rh4nDmH2p/wvotkx1oMKdhFglYcAITlk9ucEUf+CDuSdTAFFeKg9+fPqwKqWZRJZPQXqV3pGZ1/JS7gPnBFGZojW44eJufkBeiW3pbBvm/cKOkTnb8o4oltYUJsirYSQCCG+sDtxUAuGxuDCv8p+r8dWE1z5+xKclQIDAQAB
private_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VJy4iv9xwKBgFzW8+kxn2vWxz1WrPzBdtZOwothB0V6G1M7QXhONag+ylKHV4TAKexFn55Onky6mz6K0f7cVeBtsnEonKD0Gf5Xe1aHQEt225ndHMXCe60uFKxfr9y6vIVpvB1vmLkhfOSPsrmUJpDoVzkKr06RPJTCY0LRiag/YQa9XHxpSPcpAoGAKbsiJnudyJjtLhmqWbkbXjNA4n515FjY6YPzH3RDnVJyiKVuGoc+vv0bkYEvAd3HzWSq++FdDTiHQbictFsEyb59McnlSFIv/C2Orptfkq6iKTzMxIBO6/fa6fF2vss5L5rtr33S38VJNTRjAOY/mH74BtV72rRY4LA40G+keRECgYEAiGg0DYxcSGf2bEP1WESYPTTdgS5ke1niIwZ00SgtkIjPSVgTCmf4Tciys6lGSe/Oqnvk24VR6pz07wzcbH92AURVaeqiEvVuVonzA6Yl0jxeOIM31S1BSBJRT8kDijuvwoJu2tPoZG0306KF9L8pyy1Z6cTTmIfGR0NpZCHWPSg=
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment