Skip to content

Instantly share code, notes, and snippets.

@nathancyam
Created June 16, 2013 07:34
Show Gist options
  • Save nathancyam/5791287 to your computer and use it in GitHub Desktop.
Save nathancyam/5791287 to your computer and use it in GitHub Desktop.
md5 magic
public String getMD5(String mobilePassword) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
String fullHash = mobilePassword + getDate();
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