public static boolean isSignatureValid ( String payload , String signature , String appSecret ) { try { final Mac mac = Mac . getInstance ( HMAC_SHA1 ) ; mac . init ( new SecretKeySpec ( appSecret . getBytes ( ) , HMAC_SHA1 ) ) ; final byte [ ] rawHmac = mac . doFinal ( payload . getBytes ( ) ) ; final String expected = signature . substring ( 5 ) ; final String actual = bytesToHexString ( rawHmac ) ; return expected . equals ( actual ) ; } catch ( NoSuchAlgorithmException | InvalidKeyException e ) { throw new RuntimeException ( e ) ; } }
Verifies the provided signature of the payload .