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 IDplatformId = 50 # your platform ID
secret = 'your-api-key'
body = {
"orderId": "your-transaction-identifier",
"paymentId": 90,
"amount": "100.00",
"platformId": 50 # your platform ID
}$platformId = 50; //your platform ID
$secret = 'your-api-key';
$body = [
"orderId" => "your-transaction-identifier",
"paymentId" => 90,
"amount" => "100.00",
"platformId" => $platformId //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();
}
serialized_body = json.dumps(body, separators=(',', ':'), ensure_ascii=False)
signature_contract = f"{platform_id};{serialized_body};{secret}"
signature = hmac.new(secret.encode(), signature_contract.encode(), hashlib.sha256).hexdigest()Step 2 - Execution of the Request
Signature use cases:
When you call us, you should send the
x-signatureheader, so we can validate the payload data integrity.When you receive a response, you must validate the
x-signatureheader presence and validate that it is valid.When you receive a callback, you must validate the
x-signatureheader presence and validate that it is valid.
Postman create signature Pre-request Script:
Last updated