Java MD5 String md5(String input)

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

Description

md

License

Open Source License

Declaration

public static String md5(String input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String input) {

        String md5 = null;/*w  ww. ja v  a2s  .  co m*/

        if (null == input)
            return null;

        try {

            // Create MessageDigest object for MD5
            MessageDigest md = MessageDigest.getInstance("MD5");

            // Update input string in message digest
            try {
                md.update(input.getBytes("utf-8"), 0, input.length());
            } catch (UnsupportedEncodingException e) {
                throw new AssertionError(e);
            }

            // Converts message digest value in base 16 (hex)
            md5 = new BigInteger(1, md.digest()).toString(16);

        } catch (NoSuchAlgorithmException e) {

            e.printStackTrace();
        }
        return md5;
    }
}

Related

  1. md5(String input)
  2. md5(String Input)
  3. md5(String input)
  4. md5(String input)
  5. md5(String input)
  6. md5(String input)
  7. md5(String input)
  8. md5(String input)
  9. md5(String input)