Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Validate Alma webhook signature in Java
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);
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]))));

This comment has been minimized.

Copy link
Owner Author

jweisman commented Jul 14, 2019

$ javac
$ java ValidateSignature [KEY] ../json.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.