java 用hmac-sha1进行签名

    public static String getSignature(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
// String Token = "O-xJVg7ZEXrtjWDNhzu05R7iZtyyXmv6NGt-xymKg0eOLCwwBCIgBBaDqJabzbPVCez1BvcI8q7blDGy4ZeCQQ";
String key = "O-xJVg7ZEXrtjWDNhzu05R7iZtyyXmv6NGt-xymKg0eOLCwwBCIgBBaDqJabzbPVCez1BvcI8q7blDGy4ZeCQQ";
System.out.println(key);
String request = s.toLowerCase();
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
mac.init(keySpec);
mac.update(request.getBytes());
byte[] encryptedBytes = mac.doFinal();
return Base64.encodeBase64String(encryptedBytes);
}
posted @ 2016-04-19 22:51  xiaojiayu  阅读(2458)  评论(0编辑  收藏  举报