Android开发常用工具方法

来源:互联网 发布:网络诈骗报警电话1245 编辑:程序博客网 时间:2024/06/05 04:23

MD5处理

 /**     * 对String 进行md5加密     *     * @param input     * @return 32位字符串     */public static String md5(String input) {        String result = input;        if (input != null && !"".equals(input)) {            MessageDigest md; // or "SHA-1"            try {                md = MessageDigest.getInstance("MD5");                md.update(input.getBytes());                BigInteger hash = new BigInteger(1, md.digest());                result = hash.toString(16);                while (result.length() < 32) {                    result = "0" + result;                }            } catch (NoSuchAlgorithmException e) {                e.printStackTrace(); // To change body of catch statement use                // File | Settings | File Templates.            }        }        return result;}

Base64处理:

public static String base64Encode(String input ){String  result = new String(Base64.encode(input.getBytes(),Base64.DEFAULT));        return  result;}
0 0
原创粉丝点击