使用java进行MD5加密:
public class Demo1 {
private static char[] md5Str = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static String str = null;
private static String md5(String source) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
byte[] temp = md.digest(source.getBytes());
char[] cha = new char[temp.length * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
byte b = temp[i];
cha[k++] = md5Str[b >>> 4 & 0xf];
cha[k++] = md5Str[b & 0xf];
str = new String(cha);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return str;
}
public static void main(String[] args) {
System.out.println("加密后的md5 :"+md5("a"));
}
}
a加密后的md5 :0cc175b9c0f1b6a831c399e269772661