Created
November 23, 2021 01:38
-
-
Save mrmuscle1234/20c9d46d163fee66528449c0ea8419a7 to your computer and use it in GitHub Desktop.
HMAC signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// base string - this string will be used to generate mac signature. | |
StringBuilder baseString = new StringBuilder(); | |
/* | |
* The order is CRITICAL! And no "\n" at the end. | |
* | |
* Timestamp + \n + nonce + \n+ httpmethod + \n + | |
* host + \n + path + \n + bodyHash | |
*/ | |
String newline = "\n"; | |
baseString.append(ts).append(newline).append(nonce).append(newline) | |
.append(host).append(newline).append(resourcePath).append(newline) | |
.append(bodyHash); | |
// Generate signature using client secret (crypto initialized above) | |
byte[] signatureBytes = mac.doFinal(baseString.toString().getBytes(UTF8_ENCODING)); | |
// now encode the cypher for the web | |
String signatureStr = Base64.encodeBase64String(signatureBytes); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment