美文网首页
3行代码解决MD5加密

3行代码解决MD5加密

作者: 皎洁de时光 | 来源:发表于2019-01-04 11:25 被阅读0次

    public class Md5Utils {

                /**

                * 利用MD5进行加密

                * @param str 待加密的字符串

                * @return 加密后的字符串

                * @throws NoSuchAlgorithmException

                * @throws UnsupportedEncodingException

                */

                public static String EncoderByMd5(String str) {

                        if (str == null) {

                                return null;

                        }

                        try {

                                // 确定计算方法

                                MessageDigest md5 = MessageDigest.getInstance("MD5");

                                BASE64Encoder base64en = new BASE64Encoder();

                                // 加密后的字符串

                                return base64en.encode(md5.digest(str.getBytes("utf-8")));

                        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {

                                return null;

                        }

            }

    }

    相关文章

      网友评论

          本文标题:3行代码解决MD5加密

          本文链接:https://www.haomeiwen.com/subject/qwjhrqtx.html