public class Demo {
/**
* @param args
* @throws NoSuchAlgorithmException
*/
public static void main(String[] args) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("md5");
String password = "123456";
byte [] bytes = digest.digest(password.getBytes());
StringBuffer buffer = new StringBuffer();
for(byte b: bytes){
int number = b & 0xff;//加盐
String hex = Integer.toHexString(number);
if(hex.length()==1){
buffer.append("0");
}
buffer.append(hex);
}
//md5加密后的值
System.out.println(buffer);
}
}