public WebhookNotification parse(String signature, String payload) { Pattern p = Pattern.compile("[^A-Za-z0-9+=/\n]"); Matcher m = p.matcher(payload); if (m.find()) { throw new InvalidSignatureException("payload contains illegal characters"); } validateSignature(signature, payload); String xmlPayload = new String(Base64.decodeBase64(payload)); NodeWrapper node = NodeWrapperFactory.instance.create(xmlPayload); return new WebhookNotification(node); }
private String buildPayload(WebhookNotification.Kind kind, String id) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String timestamp = dateFormat.format(new Date()); String payload = "<notification><timestamp type=\"datetime\">" + timestamp + "</timestamp><kind>" + kind + "</kind><subject>" + subjectXml(kind, id) + "</subject></notification>"; return Base64.encodeBase64String(payload.getBytes()).trim(); }
public static String decodeClientToken(String rawClientToken) { String decodedClientToken = new String(Base64.decodeBase64(rawClientToken), Charset.forName("UTF-8")); return decodedClientToken.replace("\\u0026", "&"); }