Created
June 16, 2013 07:34
-
-
Save nathancyam/5791287 to your computer and use it in GitHub Desktop.
md5 magic
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
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