public static String hmacSHA1(String data,String key) {
String result = "";
byte[] bytesKey = key.getBytes();
final SecretKeySpec secretKey = new SecretKeySpec(bytesKey, "HmacSHA1");
try {
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
final byte[] macData = mac.doFinal(data.getBytes());
byte[] hex = new Hex().encode(macData);
result = new String(hex, "ISO-8859-1");
} catch (NoSuchAlgorithmException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (InvalidKeyException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return result;
}
Java对PHP服务器hmac_sha1签名认证方法的匹配实现 的另一种方式
最新推荐文章于 2021-08-10 10:03:37 发布