Java MD5 String MD5(String message)

Here you can find the source of MD5(String message)

Description

MD

License

Open Source License

Declaration

static String MD5(String message) 

Method Source Code

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

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

public class Main {
    static String MD5(String message) {
        try {//from  ww w.  j  a  v  a2  s.  c  o m
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(message.getBytes());
            byte[] digest = m.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            String hash = bigInt.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hash.length() < 32) {
                hash = "0" + hash;
            }
            return hash;
        } catch (NoSuchAlgorithmException nsae) {
            return "";
        }
    }
}

Related

  1. MD5(String md5)
  2. md5(String message)
  3. md5(String message)
  4. MD5(String message)
  5. md5(String message)
  6. md5(String orgin)
  7. md5(String pass)
  8. md5(String password)
  9. md5(String password)