Java MD5 String md5(String strs)

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

Description

md

License

Apache License

Declaration

public static String md5(String strs) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5(String strs) {
        byte[] source = strs.getBytes();
        char str[] = new char[16 * 2];
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        MessageDigest md;/* w w  w .  j  a va 2s .c  o m*/
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(source);
            byte tmp[] = md.digest();
            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];
            }
        } catch (NoSuchAlgorithmException e) {
        }
        return new String(str);

    }
}

Related

  1. md5(String string)
  2. md5(String string)
  3. md5(String string)
  4. md5(String string)
  5. MD5(String string)
  6. md5(String target)
  7. md5(String text)
  8. MD5(String text)
  9. MD5(String text)