當前位置: 首頁>>代碼示例>>Java>>正文


Java SignatureAlgorithm.HS256屬性代碼示例

本文整理匯總了Java中io.jsonwebtoken.SignatureAlgorithm.HS256屬性的典型用法代碼示例。如果您正苦於以下問題:Java SignatureAlgorithm.HS256屬性的具體用法?Java SignatureAlgorithm.HS256怎麽用?Java SignatureAlgorithm.HS256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在io.jsonwebtoken.SignatureAlgorithm的用法示例。


在下文中一共展示了SignatureAlgorithm.HS256屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Gerate

public static String Gerate(String issuer, int idSubject, int hours) {

        //The JWT signature algorithm we will be using to sign the token
        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        
        //Hours to milliseconds
        long ttlMillis = hours * 3600000;
        String subject = String.valueOf(idSubject);
        
        long nowMillis = System.currentTimeMillis();
        Date now = new Date(nowMillis);
        
        //We will sign our JWT with our ApiKey secret
        byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(Parameters.TOKENKEY);
        Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());

        //Let's set the JWT Claims
        JwtBuilder builder = Jwts.builder().setIssuedAt(now)
                                    .setSubject(subject)
                                    .setIssuer(issuer)
                                    .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 builder.compact();
    }
 
開發者ID:Montanheiro,項目名稱:SistemaAlmoxarifado,代碼行數:32,代碼來源:Token.java

示例2: 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;
    }
}
 
開發者ID:juiser,項目名稱:juiser,代碼行數:11,代碼來源:ConfigJwkResolver.java

示例3: create

/**
 * Method creates the JWT to be sent to the client
 * Sends the username and userId
 * 
 * @param user object holding user information
 * @return JavaScript Web Token
 */
public static String create(User user) {
	
	if(user == null) {
		return null;
	}
	
	SignatureAlgorithm signAlgor = SignatureAlgorithm.HS256;
	
	Key key = new SecretKeySpec(getSecret(), signAlgor.getJcaName());
	
	String id = Integer.toString(user.getUserId());
	
	JwtBuilder token = Jwts.builder().setId(id).setSubject(user.getUsername()).signWith(signAlgor, key);
	
	return token.compact();
	
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:24,代碼來源:TokenService.java

示例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;
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:9,代碼來源:JwtUtils.java


注:本文中的io.jsonwebtoken.SignatureAlgorithm.HS256屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。