Java MD5 String md5(String source)

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

Description

md

License

Apache License

Declaration

public static String md5(String source) throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.NoSuchAlgorithmException;

public class Main {
    private final static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f' };

    public static String md5(String source) throws NoSuchAlgorithmException {
        java.security.MessageDigest md;
        md = java.security.MessageDigest.getInstance("MD5");

        md.update(source.getBytes());//from   w  w  w. ja va  2 s . co m
        byte tmp[] = md.digest();
        char str[] = new char[16 * 2];
        int k = 0;
        for (int i = 0; i < 16; i++) {
            byte byte0 = tmp[i];
            str[k++] = hexDigits[byte0 >>> 4 & 0xf];
            str[k++] = hexDigits[byte0 & 0xf];
        }
        String retStr = new String(str);
        return retStr;
    }
}

Related

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