public static String md555(String plainText) throws UnsupportedEncodingException { byte[] secretBytes = null; try { secretBytes = MessageDigest.getInstance("md5").digest( plainText.getBytes()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("没有md5这个算法!"); } String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字 // 若是生成数字未满32位,须要前面补0 for (int i = 0; i < 32 - md5code.length(); i++) { md5code = "0" + md5code; } return md5code; }
这里会出现的问题是字符串编码问题,若是不进行编码的话有可能会产生不同的密文。这里只须要改为算法
plainText.getBytes(“utf-8”)就能够了。