Example of a signature

How to generate signatures?

Security

All the communication against and from our API will be signed and the signature must be included as header. This signature allows us to certificate data integrity within the communication.

Prerequisites

Integer platformId = "50"; //your platform ID
String secret = "your-api-key";

JSONObject body = new JSONObject();
body.put("orderId", "your-transaction-identifier");
body.put("paymentId", 90);
body.put("amount", "100.00");
body.put("platformId", 50); //your platform ID

Note: The previous body is an example, since it is dynamic and the signature can change according to the body of the request or response.

Step 1 - Create signature.

    ...
    ObjectMapper objectMapper = new ObjectMapper();
    String bodyJson = objectMapper.writeValueAsString(body);
    String signatureContract = platformId + ";" + bodyJson + ";" + secret;
    String signature = generateSignature(signatureContract, secret);
    ...
    
// Helper function to generate HMAC-SHA256 signature
private String generateSignature(String signatureContract, String secret) throws NoSuchAlgorithmException, InvalidKeyException {
    Mac sha256HMAC = Mac.getInstance("HmacSHA256");
    SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
    sha256HMAC.init(secretKey);
    byte[] hash = sha256HMAC.doFinal(signatureContract.getBytes(StandardCharsets.UTF_8));
    StringBuilder result = new StringBuilder();
    for (byte b : hash) {
        result.append(String.format("%02x", b));
    }
    return result.toString();
}
    

Step 2 - Execution of the Request

Signature use cases:

  1. When you call us, you should send the x-signature header, so we can validate the payload data integrity.

  2. When you receive a response, you must validate the x-signature header presence and validate that it is valid.

  3. When you receive a callback, you must validate the x-signature header presence and validate that it is valid.

Postman create signature Pre-request Script:

Last updated