On This Page
REST API
Generating a Hash of the Message Body
Generate a Base64-encoded SHA-256 hash of the message, and place the hash in the header's
digest
field. This hash is used to validate the integrity of the
message at the receiving end.Follow these steps to generate the hash:
- Generate the SHA-256 hash of the JSON payload (body of the message).
- Encode the hashed string to Base64.
- Add the message body hash to thedigestheader field.
- Add the hash algorithm used to thedigestAlgorithmheader field.
Example: Digest Header Field
digest: NmFlNTQ1OWJjOGE3ZDZhNGIyMDNlOGE3MzRkNmE2MTY3MjUxMzQwODhlMTMyNjFmNWJiY2VmYzE0MjRmYzk1Ng==
Example: DigestAlgorithm Header Field
digestAlgorithm: SHA-256
Code Example: Creating a Message Hash Using Command Line Tools
Generate the SHA-256 hash using the
shasum
tool.echo -n "{"clientReferenceInformation":{"code":"TC50171_3"},"paymentInformation":{"card":{"number": "4111111111111111","expirationMonth":"12","expirationYear":"2031"}},"orderInformation":{"amountDetails": {"totalAmount":"102.21","currency":"USD"},"billTo”:{“firstName":"John","lastName":"Doe","address1": "1MarketSt","locality":"sanfrancisco","administrativeArea":"CA","postalCode":"94105","country":"US", "email":"","phoneNumber":"4158880000"}}}" | shasum -a 256
Base64-encode the hash value using the
base64
tool.echo -n "1d079144580f47ccba9d4e4ee51d295d00fa0f197f61345ff125aa6605f91795" | base64
Code Example: Creating a Message Hash Using C#
public static string GenerateDigest() { var digest = ""; var bodyText = "{ your JSON payload }"; using (var sha256hash = SHA256.Create()) { byte[] payloadBytes = sha256hash .ComputeHash(Encoding.UTF8.GetBytes(bodyText)); digest = Convert.ToBase64String(payloadBytes); digest = digest; } return digest; }
Code Example: Creating a Message Using Java
public static String GenerateDigest() throws NoSuchAlgorithmException { String bodyText = "{ your JSON payload }"; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(bodyText.getBytes(StandardCharsets.UTF_8)); byte[] digest = md.digest(); return Base64.getEncoder().encodeToString(digest); }