Java MD5 Hash md5Hash(String content)

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

Description

md Hash

License

Open Source License

Declaration

public static String md5Hash(String content) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static String md5Hash(String content) {
        byte[] bytesOfMessage = null;
        byte[] theDigest = null;

        try {/*from w w  w.java 2 s  .c om*/
            bytesOfMessage = content.getBytes("UTF-8");

            MessageDigest md = MessageDigest.getInstance("MD5");
            theDigest = md.digest(bytesOfMessage);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return theDigest == null ? null : convertDigestToString(theDigest);
    }

    private static String convertDigestToString(byte[] digest) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            result.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
        }

        return result.toString();
    }
}

Related

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