Java MD5 String md5(String text)

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

Description

returning a MD5 hash string

License

Open Source License

Parameter

Parameter Description
text String

Return

String

Declaration

public static String md5(String text) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*  w ww.  j  a va 2 s.c om*/
     * returning a MD5 hash string
     * 
     * @param text String
     * @return String
     */
    public static String md5(String text) {
        try {
            if (text == null) {
                return "";
            }

            byte[] digest = MessageDigest.getInstance("MD5").digest(text.getBytes());
            StringBuffer sb = new StringBuffer();

            for (int i = 0; i < digest.length; i++) {
                sb.append(Integer.toString((digest[i] & 0xf0) >> 4, 16));
                sb.append(Integer.toString(digest[i] & 0x0f, 16));
            }

            return sb.toString();
        } catch (NoSuchAlgorithmException nsae) {
            return null;
        }
    }
}

Related

  1. md5(String text)
  2. md5(String text)
  3. MD5(String text)
  4. md5(String text)
  5. MD5(String text)
  6. MD5(String text)
  7. MD5(String text)
  8. md5(String text)
  9. md5(String text)