首页 > 系统服务 > 详细

HMAC256 Token

时间:2019-04-10 10:04:44      阅读:372      评论:0      收藏:0      [点我收藏+]

依赖包:

<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>

   

使用

    Algorithm.HMAC256(uerPassword)  使用HMAC256加密算法,生成签名。

    具体如下:


public static String sign(String username, Integer role, Integer userId, String secret, long expireTimeInMilliSeconds) { try { //设置过期时间:获取当前时间+过期时间(毫秒) Date date = new Date(System.currentTimeMillis() + expireTimeInMilliSeconds); //设置签名的加密算法:HMAC256 Algorithm algorithm = Algorithm.HMAC256(secret); // 附带username信息 return JWT.create().withClaim("username", username).withClaim("role", role).withClaim("uerId", userId).withExpiresAt(date).sign(algorithm); } catch (UnsupportedEncodingException e) { return null; } }

  

 

HMAC256 Token

原文:https://www.cnblogs.com/qq1141100952com/p/10681475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!