MD5 is a secure hashing algorithm, input two different plaintext will not get the same output value, according to the output value, can not get the original plaintext, that is, its process is irreversible; So to decrypt MD5 there is no ready-made algorithm, only with the poor lifting method, the possible clear text, with the MD5 algorithm hash, The resulting hash value and the original data form a one-to-one mapping table, through the comparison in the table than the crack cipher MD5 algorithm hash value, by matching from the mapping table to find out the original plaintext corresponding to the decryption password.
Importjava.security.MessageDigest; Public classPassword {Private Final StaticString[] hexdigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D", "E", "F" }; //hexadecimal number-to-character mapping array /**encrypt the inputstring .*/ Public Staticstring Createpassword (String inputstring) {returnencodeByMD5 (inputstring);} /*** Verify that the password entered is correct * *@paramPassword * Real password (encrypted true password) *@paraminputstring * Input String *@returnvalidation result, Boolean type*/ Public Static BooleanAuthenticatepassword (string password, string inputstring) {if(Password.equals (encodeByMD5 (inputstring))) {return true; } Else { return false; } } /**MD5 encoding A string*/ 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 ()); //turns the resulting byte array into a string returnString resultstring =bytearraytohexstring (results); returnresultstring.touppercase (); } Catch(Exception ex) {ex.printstacktrace (); } } return NULL; } /*** Rotate byte array to hexadecimal string * *@paramb * byte array *@returnhexadecimal string*/ Private StaticString bytearraytohexstring (byte[] b) {StringBuffer RESULTSB=NewStringBuffer (); for(inti = 0; i < b.length; i++) {resultsb.append (bytetohexstring (b[i)); } returnresultsb.tostring ();} /*** Converts a byte into a string of 16 binary form*/ Private StaticString bytetohexstring (byteb) {intn =b; if(N < 0) n= 256 +N; intD1 = n/16; intD2 = n 16; returnHEXDIGITS[D1] +HEXDIGITS[D2];} Public Static voidMain (string[] args) {String password= Password.createpassword ("Huangcheng"); System.out.println ("String for Huangcheng with MD5 digest:" +password); String inputstring= "Huangchenghuangcheng"; System.out.println ("Does the Huangchenghuangcheng match the password?" " +Password.authenticatepassword (Password, inputstring)); InputString= "Huangcheng"; System.out.println ("Does the Huangcheng match the password?" " +Password.authenticatepassword (Password, inputstring)); } }
MD5 Encrypted Java edition