Java MD5 String md5(String src)

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

Description

md

License

Open Source License

Declaration

public static String md5(String src) 

Method Source Code


//package com.java2s;
import java.security.MessageDigest;

public class Main {

    public static String md5(String src) {
        try {/* w  ww  .  jav a 2  s .  c om*/
            StringBuffer buffer = new StringBuffer();
            char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            byte[] bytes = src.getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] targ = md.digest(bytes);
            System.out.println(targ.toString());
            for (byte b : targ) {
                buffer.append(chars[(b >> 4) & 0x0F]);
                buffer.append(chars[b & 0x0F]);
            }
            return buffer.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. md5(String source)
  2. md5(String source, int bit)
  3. MD5(String sourceStr)
  4. MD5(String src)
  5. md5(String src)
  6. md5(String src)
  7. md5(String srcStr)
  8. md5(String str)
  9. md5(String str)