本文整理匯總了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());
}