Skip to main content

Generate Signature

The signature is required to authenticate and initiate API request for checkout. It is generated using HMAC-SHA512 encryption with a secret key and concatenated request parameters.

Implementation Example - Java​

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;

public class HmacSignatureGenerator {

public static String generateSignature(String secretKey, String concatenatedValues) {
try {
// Compute HMAC-SHA512
Mac sha512HMAC = Mac.getInstance("HmacSHA512");
SecretKeySpec keySpec = new SecretKeySpec(
secretKey.getBytes(StandardCharsets.UTF_8),
"HmacSHA512"
);
sha512HMAC.init(keySpec);

byte[] hashBytes = sha512HMAC.doFinal(
concatenatedValues.getBytes(StandardCharsets.UTF_8)
);

// Convert bytes to lowercase hex string
StringBuilder hash = new StringBuilder();
for (byte b : hashBytes) {
hash.append(String.format("%02x", b));
}
return hash.toString();
} catch (Exception e) {
throw new UPGException("Error generating HMAC-SHA512 signature");
}
}
}

Parameters​

Secret Key​

The secretKey is a unique string value obtained from the My Profile section in the Merchant Portal. This key is generated automatically during merchant account creation.

Concatenated Values​

The concatenatedValues is a string created by concatenating request parameter values in alphabetical order of keys, without any whitespaces.

Example Request Object:

{
"merchantId": 7,
"orderId": "teett",
"merchantName": "Test Company",
"amount": "89.99",
"paymentMethod": "test",
"description": "Payment for order #123",
"merchantCustomerName": "Dummy user",
"merchantCustomerPhoneNumber": "9800000000"
}

Alphabetically Ordered Keys: amount, description, merchantCustomerName, merchantCustomerPhoneNumber, merchantId, merchantName, orderId, paymentMethod

Concatenated String (no whitespaces):

89.99Paymentfororder#123Dummyuser9800000007TestCompanyteettTest
note
  • Retrieve the secretKey from your Merchant Portal profile.
  • Concatenate request parameter values in alphabetical key order without whitespaces.
  • Call generateSignature(secretKey, concatenatedValues) to obtain the signature.
  • Include the signature in your API request headers for checkout.