本文整理匯總了Java中io.jsonwebtoken.SignatureAlgorithm.HS512屬性的典型用法代碼示例。如果您正苦於以下問題:Java SignatureAlgorithm.HS512屬性的具體用法?Java SignatureAlgorithm.HS512怎麽用?Java SignatureAlgorithm.HS512使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類io.jsonwebtoken.SignatureAlgorithm
的用法示例。
在下文中一共展示了SignatureAlgorithm.HS512屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createJWT
/**
* 創建jwt
* @param id
* @param subject
* @param ttlMillis
* @return
* @throws Exception
*/
public String createJWT(String id, String subject, long ttlMillis) throws Exception {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS512;
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
SecretKey key = generalKey();
JwtBuilder builder = Jwts.builder()
.setId(id)
.setIssuedAt(now)
.setSubject(subject)
.signWith(signatureAlgorithm, key);
if (ttlMillis >= 0) {
long expMillis = nowMillis + ttlMillis;
Date exp = new Date(expMillis);
builder.setExpiration(exp);
}
return builder.compact();
}
示例2: JsonWebTokenUtility
public JsonWebTokenUtility() {
// 這裏不是真正安全的實踐
// 為了簡單,存儲一個靜態key在這裏
signatureAlgorithm = SignatureAlgorithm.HS512;
String encodedKey = "L7A/6zARSkK1j7Vd5SDD9pSSqZlqF7mAhiOgRbgv9Smce6tf4cJnvKOjtKPxNNnWQj+2lQEScm3XIUjhW+YVZg==";
secretKey = deserializeKey(encodedKey);
}
示例3: getAlgorithm
static SignatureAlgorithm getAlgorithm(byte[] hmacSigningKeyBytes) {
Assert.isTrue(hmacSigningKeyBytes != null && hmacSigningKeyBytes.length > 0,
"hmacSigningBytes cannot be null or empty.");
if (hmacSigningKeyBytes.length >= 64) {
return SignatureAlgorithm.HS512;
} else if (hmacSigningKeyBytes.length >= 48) {
return SignatureAlgorithm.HS384;
} else { //<= 32
return SignatureAlgorithm.HS256;
}
}
示例4: isSymmetric
/**
* Check if given <code>signatureAlgorithm</code> requires a symmetric (shared) key
* @param signatureAlgorithm SignatureAlgorithm
* @return <code>true</code> if given algorithm requires a symmetric (shared) key
*/
public static boolean isSymmetric(SignatureAlgorithm signatureAlgorithm) {
return SignatureAlgorithm.HS256 == signatureAlgorithm || SignatureAlgorithm.HS384 == signatureAlgorithm
|| SignatureAlgorithm.HS512 == signatureAlgorithm;
}