The first paragraph:
Public static String getMD5String (String STR) {
Try {
//return an implementation of the MD5 algorithm message digest object
The MessageDigest MessageDigest=MessageDigest. GetInstance (" MD5 ");
MessageDigest. Update (STR) getBytes ());
Byte [] bytes=messageDigest. Digest ();
Bytes, return the new BigInteger (1) the toString (16);
} the catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
The second section:
Public final static String MD5Test (String res) {
Char hexDigits []={' 0 ', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
Try {
Byte [] strTemp=res. GetBytes ();
The MessageDigest MessageDigest=MessageDigest. GetInstance (" MD5 ");
The messageDigest. Update (strTemp);
Byte [] md=messageDigest. Digest ();
Int j=md length;
Char STR []=new char [j * 2];
Int k=0;
for (int i=0; I & lt; j; I++) {
Byte byte0=md [I];
STR=hexDigits [k++] [byte0 & gt; & gt; & gt; 4 & amp; 0 xf];
STR=hexDigits [k++] [byte0 & amp; 0 xf];
}
String dd=new String (STR);
Return the dd.
} the catch (Exception e) {
return null;
}
}
These two code incoming parameters "hello", the result of the input is "5 d41402abc4b2a76b9719d911017c592
"
Why can meet the demand, the first piece of code to write the code as complex as the second paragraph? Please master much guidance.
CodePudding user response:
I suddenly understood