Skip to content

Instantly share code, notes, and snippets.

@teohm
Created September 8, 2015 14:19
Show Gist options
  • Save teohm/d5099219095c68c72fe1 to your computer and use it in GitHub Desktop.
Save teohm/d5099219095c68c72fe1 to your computer and use it in GitHub Desktop.
Examples of md5 checksum signature calculation for ReferralCandy advanced integration
import java.util.*;
import java.lang.*;
import java.io.*;
import java.security.*;
import java.math.*;
class MD5Example
{
public static void main (String[] args) throws java.lang.Exception
{
String email = "[email protected]";
String firstName = "Joe";
String purchaseAmount = "2.60";
String purchaseTimestamp = "1441692412"; // epoch time in seconds
String secretKey = "f88346aa80c044a8b5c4f291d00ba555";
String data = String.join(",", email, firstName, purchaseAmount,
purchaseTimestamp, secretKey);
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] md5 = md.digest(data.getBytes());
String signature = String.format("%032x", new BigInteger(1, md5));
System.out.println(data);
//Output: [email protected],Joe,2.60,1441692412,f88346aa80c044a8b5c4f291d00ba555
System.out.println(signature);
//Output: f1fcf14e6c9af07f90eb9364dc3dc8f4
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment