Java MD5 String md5(String inputText)

Here you can find the source of md5(String inputText)

Description

md

License

Apache License

Declaration

public static String md5(String inputText) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String inputText) {
        if (inputText == null || "".equals(inputText.trim())) {
            throw new IllegalArgumentException("please input un-null value");
        }// www.j a v a  2  s  .c o  m

        String encryptText = null;
        try {
            MessageDigest m = MessageDigest.getInstance("md5");
            m.update(inputText.getBytes());
            byte s[] = m.digest();
            return hex(s);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "" + inputText.hashCode();
        }
    }

    private static String hex(byte[] arr) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; ++i) {
            sb.append(Integer.toHexString((arr[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    }
}

Related

  1. md5(String input)
  2. md5(String input)
  3. md5(String input)
  4. MD5(String input)
  5. MD5(String inputString)
  6. md5(String inStr)
  7. md5(String key)
  8. md5(String md5)
  9. MD5(String md5)