公司用到md5加密,今天做了一个小Demo学习一下。
工具类:
public class Md5Util { public static String md5(String String){ MessageDigest md5=null; try {// MD5的加密类 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 ""; }}Ma.class实践:protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String String=Md5Util.md5("android"); Log.e("md5","android经过md5加密后得到:"+String);}得到结果:
新闻热点
疑难解答