Last active
July 14, 2019 18:17
-
-
Save jweisman/2a0326e0e8d7978639229a6dbc9f55f2 to your computer and use it in GitHub Desktop.
Validate Alma webhook signature in Java
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
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.Base64; | |
import javax.crypto.Mac; | |
import javax.crypto.spec.SecretKeySpec; | |
public class ValidateSignature { | |
public static String encode(String key, byte[] data) throws Exception { | |
Mac hmac = Mac.getInstance("HmacSHA256"); | |
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), key); | |
hmac.init(secret_key); | |
return Base64.getEncoder().encodeToString(hmac.doFinal(data)); | |
} | |
public static void main(String [] args) throws Exception { | |
System.out.println(encode(args[0], Files.readAllBytes(Paths.get(args[1])))); | |
} | |
} |
Author
jweisman
commented
Jul 14, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment