Java MD5 String md5Encrypt(String str)

Here you can find the source of md5Encrypt(String str)

Description

md Encrypt

License

Open Source License

Declaration

public static String md5Encrypt(String str) 

Method Source Code

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

import java.security.MessageDigest;

public class Main {
    static MessageDigest m_md5;

    public static String md5Encrypt(String str) {
        byte[] bytes = null;
        try {//  w w  w . ja va  2  s.c o m
            bytes = str.getBytes("UTF-8");
        } catch (Exception e) {
            bytes = str.getBytes();
        }

        byte messageDigest[] = null;
        synchronized (m_md5) {
            m_md5.update(bytes);
            messageDigest = m_md5.digest();
        }

        StringBuffer hexString = new StringBuffer();
        int d;
        for (int i = 0; i < messageDigest.length; i++) {
            d = messageDigest[i];
            if (d < 0)
                d += 256;
            if (d < 16)
                hexString.append("0");
            hexString.append(Integer.toHexString(d));
        }
        return hexString.toString();
    }
}

Related

  1. md5Digest(String word)
  2. md5DigestPassword(String password)
  3. md5EncriptionPassword(String str)
  4. md5encrypt(String phrase)
  5. md5Encrypt(String str)
  6. md5Encryption(String str)
  7. md5File(File f)
  8. md5file(File file)
  9. md5FromFile(File file)