Skip to content

Instantly share code, notes, and snippets.

Embed
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);
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]))));
}
}
@jweisman

This comment has been minimized.

Copy link
Owner Author

commented Jul 14, 2019

$ javac ValidateSignature.java
$ java ValidateSignature [KEY] ../json.txt
I/OLK158f+VJrF0cy8bNszVo6rcwl6/97p6Xqm9cqMM=
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.