Skip to content

Instantly share code, notes, and snippets.

// 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
*/
@mrmuscle1234
mrmuscle1234 / hmac_token_creation.java
Created November 23, 2021 00:10
hmac token creation
import java.util.UUID;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class AuthorizationMacHeader {
private static final String HMAC_SHA256_ALGORITHM = "HmacSHA256";
private static final String AUTHORIZATION_HEADER_PREFIX = "HMAC-SHA256 ";
private static final String KEY_ID_LABEL = "keyid";