MD5加密

来源:互联网 发布:网络多媒体新闻 编辑:程序博客网 时间:2024/04/30 01:23

public static String md5(String text) {
    MessageDigest msgDigest = null;
    try {
      msgDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException("System doesn't support MD5 algorithm.");
    }
    try {
      msgDigest.update(text.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
      throw new IllegalStateException("System doesn't support your  EncodingException.");
    }
    byte[] bytes = msgDigest.digest();
    String md5Str = new String(encodeHex(bytes));
    return md5Str;
  }
0 0
原创粉丝点击