The MD5 Algorithm Implementation function in Java. the string (MD5) generated by this function is exactly the same as that generated by the C language in this blog. This can be easily replaced.
Private Static string MD5 (string input ){
If (input = NULL) | (input. Length () = 0 )){
Return "d41d8cd98f00b204e9800998ecf8427e"; // This value exists to be compatible with the C language's dll MD5 value.
}
Else {
Stringbuffer sb = new stringbuffer ();
Try {
Messagedigest algorithm = messagedigest. getinstance ("MD5 ");
Algorithm. Reset ();
Algorithm. Update (input. getbytes ());
Byte [] MD5 = algorithm. Digest ();
String singlebytehex = "";
For (INT I = 0; I <md5.length; I ++ ){
Singlebytehex = integer. tohexstring (0xff & MD5 [I]);
If (singlebytehex. Length () = 1 ){
SB. append ("0 ");
}
SB. append (singlebytehex. touppercase ());
}
} Catch (nosuchalgorithmexception ex ){
Ex. printstacktrace ();
}
Return sb. tostring ();
}
}