File tree Expand file tree Collapse file tree
src/main/java/com/mindee/parsing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import java .nio .file .Files ;
1010import java .nio .file .Path ;
1111import java .security .InvalidKeyException ;
12+ import java .security .MessageDigest ;
1213import java .security .NoSuchAlgorithmException ;
1314import java .util .stream .Collectors ;
1415import java .util .stream .Stream ;
@@ -99,10 +100,18 @@ public String getHmacSignature(String secretKey) {
99100 * Verify that the payload's signature matches the one received from the server.
100101 *
101102 * @param secretKey Your secret key from the Mindee platform.
102- * @param signature The signature from the "X-Mindee-Hmac- Signature" HTTP header.
103+ * @param signature The signature from the "X-Signature" HTTP header.
103104 * @return true if the signatures match.
104105 */
105106 public boolean isValidHmacSignature (String secretKey , String signature ) {
106- return signature .equals (getHmacSignature (secretKey ));
107+ if (signature == null || secretKey == null ) {
108+ return false ;
109+ }
110+ byte [] expectedBytes = getHmacSignature (secretKey ).getBytes (StandardCharsets .UTF_8 );
111+ byte [] actualBytes = signature
112+ .toLowerCase (java .util .Locale .ROOT )
113+ .getBytes (StandardCharsets .UTF_8 );
114+
115+ return MessageDigest .isEqual (expectedBytes , actualBytes );
107116 }
108117}
You can’t perform that action at this time.
0 commit comments