話很少說上碼git
public static byte[] digest(String signStr) { MessageDigest md5Instance = null; try { md5Instance = MessageDigest.getInstance("MD5"); md5Instance.update(signStr.getBytes("utf-8")); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return md5Instance.digest(); }
獲得byte數據,轉16進制後的字符串加密
//加密後轉 private static String byte2Hex(byte[] bytes) { char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; int j = bytes.length; char str[] = new char[j * 2]; int k = 0; for (byte byte0 : bytes) { str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); }
最終獲得你想要的spa