Java MD5 Hash md5Hash(String in)

Here you can find the source of md5Hash(String in)

Description

md Hash

License

Apache License

Declaration

public static String md5Hash(String in) 

Method Source Code

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

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

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

public class Main {
    public static String md5Hash(String in) {
        byte[] bytesOfMessage = null;
        try {//from w  ww  . j  av  a  2s. c  o  m
            bytesOfMessage = in.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }

        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
        }
        byte[] digest = md.digest(bytesOfMessage);
        BigInteger bigInt = new BigInteger(1, digest);
        String result = bigInt.toString(16);
        // fill up with zeros to get a string with length 32
        while (result.length() < 32) {
            result = "0" + result;
        }
        return result;
    }
}

Related

  1. md5hash(byte[] input)
  2. md5Hash(byte[] key)
  3. md5Hash(String algorithm, String input)
  4. md5Hash(String buf)
  5. md5Hash(String content)
  6. md5Hash(String input)
  7. md5hash(String key)
  8. md5hash(String pass)
  9. md5Hash(String source)