当前位置: 首页>>代码示例>>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;未经允许,请勿转载。