Last active
October 16, 2020 15:34
-
-
Save summersab/b0a08d4de5ef20c79c2e62b5ff6548a8 to your computer and use it in GitHub Desktop.
SignifyD Webhook JSON Validation (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
// 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