Created
August 15, 2021 14:20
-
-
Save artem-smotrakov/933214caa4a0ed8d406b5b3389b7a71f to your computer and use it in GitHub Desktop.
Possible timing attack against MAC validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean validate(HttpRequest request, SecretKey key) throws Exception { | |
byte[] message = getMessageFrom(request); | |
byte[] signature = getSignatureFrom(request); | |
Mac mac = Mac.getInstance("HmacSHA256"); | |
mac.init(new SecretKeySpec(key.getEncoded(), "HmacSHA256")); | |
byte[] actual = mac.doFinal(message); | |
return Arrays.equals(signature, actual); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment