Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now

MD5 encryption using java

MD5 encryption using java

In this tutorial we will learn how to create md5 hash in java. To create md5 hash in java we need follow below steps.

  • Import java.math.BigInteger.
  • Import
  • Import
  • Create MessageDigest object for MD5
  • Update input string in message digest
  • Converts message digest value in base16 (hex)
  • If md5 generated successfully return md5 string else show an exception.

Below is the example class for java to generate md5 hash

package yourpackage;
import java.math.BigInteger;
public class Encrypt {
    public static String md5(String input) {
        String md5 = null;
        if (null == input) {
            return null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(input.getBytes(), 0, input.length());
            md5 = new BigInteger(1, digest.digest()).toString(16);

        } catch (NoSuchAlgorithmException e) {
        return md5;

Tags : Java, MySQL,

Views : 926

Subscribe Us

Follow Us