[阅读: 294] 2005-06-21 04:37:13
还要有源码的
JAVA 的MD5加密算法源代码 (这么简单的?!)
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));
}