MD5加密
public static String md5(String string) { if (TextUtils.isEmpty(string)) { return ""; } MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); byte[] bytes = md5.digest(string.getBytes()); String result = ""; for (byte b : bytes) { String temp = Integer.toHexString(b & 0xff); if (temp.length() == 1) { temp = "0" + temp; } result += temp; } return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
// Base64加密 String encodedString = Base64.encodeToString("kakaxi".getBytes(), Base64.DEFAULT); Log.e("tag" , "encode :" + encodedString); String decodeString = new String(Base64.decode(encodedString , Base64.DEFAULT)); Log.e("tag" , "decode :" + decodeString);