Android字符串md5加密

 Android字符串md5加密

 

[java]

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
public static String get(String id, String num) {
String str = id + num;
byte[] digest = null;
try {
digest = MessageDigest.getInstance("MD5").digest(
str.getBytes("UTF-8"));

} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StringBuilder md5 = new StringBuilder(digest.length * 2);
for (byte b : digest) {
if ((b & 0xFF) < 0x10)
md5.append("0");
md5.append(Integer.toHexString(b & 0xFF));
}
return md5.toString();
}
}

[/java]