Commit 7887fd98 by caiyt-byte

token key方式更改

parent 2f7f33fc
......@@ -18,7 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.security.Key;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
......@@ -52,6 +55,13 @@ public class TokenService {
@Autowired
private RedisCache redisCache;
private Key secretKey;
@PostConstruct
public void init() {
secretKey = new SecretKeySpec(secret.getBytes(), SignatureAlgorithm.HS512.getJcaName());
}
/**
* 获取用户身份信息
*
......@@ -162,7 +172,7 @@ public class TokenService {
private String createToken(Map<String, Object> claims) {
String token = Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret).compact();
.signWith(SignatureAlgorithm.HS512, secretKey).compact();
return token;
}
......@@ -174,7 +184,7 @@ public class TokenService {
*/
private Claims parseToken(String token) {
return Jwts.parser()
.setSigningKey(secret)
.setSigningKey(secretKey)
.parseClaimsJws(token)
.getBody();
}
......
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