Android笔记(10)MD5加密

来源:互联网 发布:c语言编写 玫瑰花 编辑:程序博客网 时间:2024/06/11 23:28
public static String getmd5(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 "";    }
原创粉丝点击