安卓开发中MD5加密

2019-07-20  本文已影响0人  今天也要努力呀y

对字符串的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 "";

    }
String mess = input.getText().toString();
                String output1 = MD5httl.md5(mess);
                output.setText(output1);
image.png
上一篇 下一篇

猜你喜欢

热点阅读