Skip to content

Instantly share code, notes, and snippets.

@summersab
Last active October 16, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save summersab/b0a08d4de5ef20c79c2e62b5ff6548a8 to your computer and use it in GitHub Desktop.
Save summersab/b0a08d4de5ef20c79c2e62b5ff6548a8 to your computer and use it in GitHub Desktop.
SignifyD Webhook JSON Validation (Java)
// Use JDK 1.8.0_66
// Test here to make life easy: https://www.jdoodle.com/online-java-compiler/
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import javax.xml.bind.DatatypeConverter;
public class Main {
public static void main(String[] args) {
try {
String key = "decryption key";
String jsonBody = "{\"escape\":\"quotes\"}";
Mac sha256HMAC = Mac.getInstance("HmacSHA256");
sha256HMAC.init(new SecretKeySpec(key.getBytes(), "HmacSHA256"));
// Output for debugging
System.out.println(key.getBytes());
byte[] hash = sha256HMAC.doFinal(jsonBody.getBytes());
// Output for debugging
System.out.println(hash);
// to base64
System.out.println(DatatypeConverter.printBase64Binary(hash));
}
catch (NoSuchAlgorithmException e) {}
catch (InvalidKeyException e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment