HmacSHA256签名加Base64编码加URL编码


/**
*先使用HmacSHA256签名,再使用Base64编码,最后进行URL 编码
*signatureReqStr : 待加密data
* secretKey : 密钥
*/
public static String getSignature(String signatureReqStr,String secretKey){
Mac sha256_HMAC ;
String result = "";
try {
sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
result = Base64.encodeBase64String(sha256_HMAC.doFinal(signatureReqStr.getBytes()));
result = URLEncoder.encode(result);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return result;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM