Closed aakashcentime closed 1 month ago
The issue is with request body that comes. Chargify calculates HMAC with partially encoded body which creates a problem.
how i solved it.
public ResponseEntity receiver(@RequestBody String requestBody, @RequestParam String id, @NotNull @RequestParam String event, @RequestHeader("X-Chargify-Webhook-Signature-Hmac-Sha-256") String hmacHeader) { requestBody= requestBody.replace("%5B","["); requestBody = requestBody.replace("%5D","]"); requestBody = requestBody.replace("+","%20");
Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec("YOUR KEY".getBytes("UTF-8"), "HmacSHA256"); sha256_HMAC.init(secret_key); System.out.println("hmacgiven: "+hmacHeader); System.out.println(Hex.encodeHexString(sha256_HMAC.doFinal(requestBody.getBytes(StandardCharsets.UTF_8))));
The issue is with request body that comes. Chargify calculates HMAC with partially encoded body which creates a problem.
how i solved it.
public ResponseEntity receiver(@RequestBody String requestBody, @RequestParam String id, @NotNull @RequestParam String event, @RequestHeader("X-Chargify-Webhook-Signature-Hmac-Sha-256") String hmacHeader) { requestBody= requestBody.replace("%5B","["); requestBody = requestBody.replace("%5D","]"); requestBody = requestBody.replace("+","%20");
Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec("YOUR KEY".getBytes("UTF-8"), "HmacSHA256"); sha256_HMAC.init(secret_key); System.out.println("hmacgiven: "+hmacHeader); System.out.println(Hex.encodeHexString(sha256_HMAC.doFinal(requestBody.getBytes(StandardCharsets.UTF_8))));