Recently, the cool interface was jointly tuned with Dongxin beiyou. In this interface, MD5 computing is required to verify the identity of each other. The other party uses Java for development.. NET development. Unfortunately, the MD5 Algorithm of the other party does not match the test siute of RFC 1321. They provided the MD5 algorithm. After multiple times of searching for information and asking people who want to ask for information, they finally achieved consistency. The code is provided for reference by people who have similar problems with me:
1. Java Edition
Code
/**
* Generate a 32-bit MD5 message digest
*
* @ Param info
* Original string message
* @ Return
*/
Public static string getdigeststr (string info ){
Try {
Byte [] res = info. getbytes ();
Messagedigest MD = messagedigest. getinstance ("MD5 ");
Byte [] result = md. Digest (RES );
For (INT I = 0; I <result. length; I ++ ){
Md. Update (result [I]);
}
Byte [] hash = md. Digest ();
Stringbuffer d = new stringbuffer ("");
For (INT I = 0; I Int v = hash [I] & 0xff;
If (v <16 ){
D. append ("0 ");
}
D. append (integer. tostring (v, 16). touppercase ());
}
Return D. tostring ();
} Catch (exception e ){
Return NULL;
}
}
2.. Net Edition
Code
/// <Summary>
/// Corresponding to the Java version of MD5 (two consecutive summaries)
/// </Summary>
/// <Param name = "info"> </param>
/// <Returns> </returns>
Public static string getdigeststr (string info)
{
Try
{
Byte [] res = system. Text. encoding. Default. getbytes (Info );
Md5cryptoserviceprovider MD = new md5cryptoserviceprovider ();
Byte [] result = md. computehash (RES );
Byte [] hash = md. computehash (result );
Stringbuilder sbuilder = new stringbuilder ();
For (INT I = 0; I {
Int v = hash [I] & 0xff;
If (v <16) sbuilder. append ("0 ");
Sbuilder. append (convert. tostring (v, 16). toupper ());
}
Return sbuilder. tostring ();
}
Catch
{
Return NULL;
}
}