MD5 Encryption MD5 is a hash algorithm with moderate encryption strength. Hashing algorithm has the following characteristics: (1) irreversible, even under the premise of known encryption process, can not be inferred from ciphertext back to plaintext. ② The length of output data is fixed. For example, the length of MD5 encryption output data is fixed to 32 characters. ③ Input data is unchanged, output data is unchanged; As the input changes, so does the output.

/** * public static String MD5 (String soucre) {// 1 CheckResult = stringCheck(soucre); // 2. If string verification fails, throw an exception if (! checkResult) { throw new RuntimeException(ACConst.MESSAGE_PWD_INVALID); Byte [] inputBytes = soucre.getBytes(); MessageDigest String algorithm = "md5"; Byte [] outputBytes = null; // 5. Try {/ / 6. Get the MessageDigest instance MessageDigest digest. = the MessageDigest getInstance (algorithm); OutputBytes = digest.digest(inputBytes); // 7. } catch (NoSuchAlgorithmException e) { e.printStackTrace(); StringBuilder StringBuilder builder = new StringBuilder(); / / (2) declare character array char [] characters = new char [] {' 0 ', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E','F' }; OutputBytes for (int I = 0; i < outputBytes.length; i++) { byte b = outputBytes[i]; Int lowValue = b&15; Int highValue = (b >> 4) &15; Char lowChar = characters[lowValue]; char lowChar = characters[lowValue]; char highChar = characters[highValue]; Builder.append (highChar).append(lowChar); } return builder.toString(); }Copy the code