Skip to content

Instantly share code, notes, and snippets.

@arran4
Forked from nathancyam/AuthHttpHandler.java
Last active December 18, 2015 13:39
Show Gist options
  • Save arran4/5791291 to your computer and use it in GitHub Desktop.
Save arran4/5791291 to your computer and use it in GitHub Desktop.
Call with:
String date = getDate();
String md5 = getMD5("passwprd", date);
checkauth(date, md5, email);
Code:
public String getMD5(String mobilePassword, String date) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
String fullHash = mobilePassword + date;
md.update(fullHash.getBytes());
byte byteData[] = md.digest();
StringBuffer hexString = new StringBuffer();
for (int i=0;i<byteData.length;i++) {
String hex=Integer.toHexString(0xff & byteData[i]);
if(hex.length()==1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
}
private String getDate(){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date();
return format.format(date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment