import java.security.*;
import java.security.spec.*;
class md5_test{
public final static string md5(string s){
char hexdigits[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
'e', 'f'};
try {
byte[] strtemp = s.getbytes();
messagedigest mdtemp = messagedigest.getinstance("md5");
mdtemp.update(strtemp);
byte[] md = mdtemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexdigits[byte0 >>> 4 & 0xf];
str[k++] = hexdigits[byte0 & 0xf];
}
return new string(str);
}
catch (exception e){
return null;
}
}
public static void main(string[] args){
//md5_test aa = new md5_test();
system.out.print(md5_test.md5("xx"));
}
菜鸟学堂: