Development encountered MD5 encryption inconsistency problem, the exclusion of context encoding, encryption content issues.
Crawled all kinds of information, and finally found the reason.
/**MD5 encryption of strings*/ Private Staticstring encodeByMD5 (String originstring) {if(Originstring! =NULL) { Try{//creates a summary of information with the specified algorithm nameMessageDigest MD = messagedigest.getinstance ("MD5"); //The summary is last updated with the specified byte array, and the summary calculation is completed byte[] results = Md.digest (Originstring.getbytes ("UTF-8")); //turns the resulting byte array into a string returnString resultstring =bytearraytohexstring (results); returnresultstring.touppercase (); } Catch(Exception ex) {ex.printstacktrace (); } } return NULL; }
Need to give encrypted content to the specified encoding format to get, compared to PHP MD5, really drunk.
It is simple to conclude that PHP does not encrypt characters according to the context-coded format. In contrast to Java encryption, which is encrypted according to the encoded format of the encrypted content, you need to specify the encoding format corresponding to the current context in order to obtain the desired encryption result.
Examples of causes:
This type of error is usually an issue with the encoding format if our console input characters are in BGK format and the Web is passed UTF-8 our toString () view content indicates that there is no difference, this results in the same string encryption after the result is different as the following small example
Import Static = "[Email protected]| | [Email protected]$%&1000]// b08f601a7b6b440dfa3ed6eb353c2d24// //
ps:http://blog.csdn.net/w627782664/article/details/7064273
Java MD5 encryption console incoming and Web incoming parameter results do not match | | Same string encryption result is different