本文整理汇总了Java中io.jsonwebtoken.SignatureAlgorithm.RS256属性的典型用法代码示例。如果您正苦于以下问题:Java SignatureAlgorithm.RS256属性的具体用法?Java SignatureAlgorithm.RS256怎么用?Java SignatureAlgorithm.RS256使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.jsonwebtoken.SignatureAlgorithm
的用法示例。
在下文中一共展示了SignatureAlgorithm.RS256属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJWT
private JwtToken createJWT(String id,
String issuer,
String subject,
String privileges,
long ttlMillis) {
// The JWT signature algorithm we will be using to sign the token
final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RS256;
final long nowMillis = System.currentTimeMillis();
final Date now = new Date(nowMillis);
// We will sign our JWT with our ApiKey secret
final Key signingKey = EncryptionUtil.getPrivateKey(
env.getProperty("service.jwt.secret"));
final Map<String, Object> claims = new HashMap<>();
claims.put("privileges", privileges);
// Let's set the JWT Claims
final JwtBuilder builder = Jwts.builder()
.setClaims(claims)
.setId(id)
.setIssuer(issuer)
.setIssuedAt(now)
.setSubject(subject)
.signWith(signatureAlgorithm, signingKey);
// If it has been specified, let's add the expiration
if (ttlMillis >= 0) {
long expMillis = nowMillis + ttlMillis;
Date exp = new Date(expMillis);
builder.setExpiration(exp);
}
// Builds the JWT and serializes it to a compact, URL-safe string
return new JwtToken(builder.compact());
}