Java MD5 String md5(String source)

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

Description

md

License

Open Source License

Declaration

public static String md5(String source) 

Method Source Code

//package com.java2s;

import java.security.MessageDigest;

public class Main {

    public static String md5(String source) {
        char hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        try {// w w  w .  ja  v  a  2  s  .co m
            byte[] bytes = source.getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes);
            bytes = md.digest();
            int j = bytes.length;
            char[] chars = new char[j * 2];
            int k = 0;
            for (int i = 0; i < bytes.length; i++) {
                byte b = bytes[i];
                chars[k++] = hexChars[b >>> 4 & 0xf];
                chars[k++] = hexChars[b & 0xf];
            }
            return new String(chars);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

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