Package com. iask. Base. MD5;
Import java. Security. messagedigest;
/**
* MD5 Encryption
*
* @ Author Li Zheng
*
*/
Public class MD5 {
Public final static string encode (string Str ){
Return encodemd5 (STR );
}
Private Final Static string encodemd5 (string s ){
Char hexdigits [] = {'0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9 ',
'A', 'B', 'C', 'D', 'E', 'E', 'F '};
Try {
Byte [] btinput = S. getbytes ();
Messagedigest mdinst = messagedigest. getinstance ("MD5 ");
Mdinst. Update (btinput );
Byte [] MD = mdinst. 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 ){
E. printstacktrace ();
Return NULL;
}
}
Public static void main (string AGRs []) {
String md2 = encode ("123456 ");
System. Out. println (md2 );
}
}