基于HmacSHA256的安全令牌_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 基于HmacSHA256的安全令牌

基于HmacSHA256的安全令牌

 2017/7/31 12:38:49  ceasarje  程序员俱乐部  我要评论(0)
  • 摘要:Macsha256_HMAC=null;BASE64Decoderdecoder=null;BASE64Encoderencoder=null;try{decoder=newsun.misc.BASE64Decoder();SecretKeysecret_key=newSecretKeySpec(decoder.decodeBuffer(sAccessKey),"HmacSHA256");sha256_HMAC=Mac.getInstance(secret_key.getAlgorithm()
  • 标签:Mac
class="java">				Mac sha256_HMAC = null;
				BASE64Decoder decoder = null;
				BASE64Encoder encoder = null;
				try {
					decoder = new sun.misc.BASE64Decoder();
					SecretKey secret_key = new SecretKeySpec(decoder.decodeBuffer(sAccessKey), "HmacSHA256");
					sha256_HMAC = Mac.getInstance(secret_key.getAlgorithm());
					sha256_HMAC.init(secret_key);
					byte[] digest = sha256_HMAC.doFinal(sStringToSign.getBytes("UTF-8"));
					encoder = new sun.misc.BASE64Encoder();
					sToken = encoder.encode(digest); 
				} catch (NoSuchAlgorithmException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvalidKeyException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
发表评论
用户名: 匿名