【发布时间】:2016-11-17 01:27:58
【问题描述】:
我正在阅读jjwt 库的概述:
构建令牌如下:
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
import java.security.Key;
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = MacProvider.generateKey();
String compactJws = Jwts.builder()
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, key)
.compact();
并且令牌被验证为:
try {
Jwts.parser().setSigningKey(key).parseClaimsJws(compactJws);
//OK, we can trust this JWT
} catch (SignatureException e) {
//don't trust the JWT!
}
SignatureAlgorithm.HS512 不用于第二个 sn-p。它是如何推断的?还是没有必要?
【问题讨论】:
标签: authentication jwt jjwt