· 8 years ago · Dec 30, 2017, 11:38 AM
1private static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
2
3 SecretKey secretKey = null;
4
5 byte[] keyBytes = keyString.getBytes();
6 secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
7
8 Mac mac = Mac.getInstance("HmacSHA1");
9
10 mac.init(secretKey);
11
12 byte[] text = baseString.getBytes();
13
14 return new String(Base64.encodeBase64(mac.doFinal(text))).trim();
15}