· 6 years ago · Jun 21, 2019, 02:00 PM
1static String generateHashKey (String apiKey, String msg) throws GeneralSecurityException{
2
3 Mac hmacSha256 = Mac.getInstance("HmacSHA256");
4 SecretKeySpec secretKey = new SecretKeySpec(apiKey.getBytes(), "HmacSHA256");
5 hmacSha256.init(secretKey);
6 byte[] bytes = hmacSha256.doFinal(msg.getBytes());
7
8 return Hex.encodeHexString(bytes).replace("-","");
9}
10
11import crypto from "crypto";
12...
13const eMessage = crypto.createHmac("SHA256", apiKey).update(message).digest("base64");