· 7 years ago · Jul 23, 2018, 08:32 PM
1public static String encode(String privateKey, String publicKey, long timestamp, String requestData) throws Exception
2 {
3 char[] hexArray = "0123456789ABCDEF".toCharArray();
4 String data = publicKey + String.valueOf(timestamp) + requestData;
5 Mac sha512_HMAC = Mac.getInstance("HmacSHA512");
6 SecretKeySpec secret_key = new SecretKeySpec(privateKey.getBytes("UTF-8"), "HmacSHA512");
7 sha512_HMAC.init(secret_key);
8 byte[] bytes = sha512_HMAC.doFinal(data.getBytes("UTF-8"));
9 char[] hexChars = new char[bytes.length * 2];
10 for ( int j = 0; j < bytes.length; j++ ) {
11 int v = bytes[j] & 0xFF;
12 hexChars[j * 2] = hexArray[v >>> 4];
13 hexChars[j * 2 + 1] = hexArray[v & 0x0F];
14 }
15 Log.e(TAG, " ENCODE STRING " + publicKey + String.valueOf(timestamp) + requestData);
16 return new String(hexChars).toLowerCase();
17 }
18
19 public static String createTransactionID() throws Exception
20 {
21 return UUID.randomUUID().toString();
22 }