Java MD5 String md5(String string)

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

Description

md

License

Open Source License

Declaration

public static String md5(String string) 

Method Source Code

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

import java.security.MessageDigest;

public class Main {
    private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();

    public static String md5(String string) {
        try {//from   ww w  .java  2 s  . c o m
            return bytesToHex(MessageDigest.getInstance("md5").digest(string.getBytes("UTF-8")));
        } catch (Exception e) {
            return string;
        }
    }

    public static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = HEX_CHARS[v >>> 4];
            hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];
        }
        return new String(hexChars);
    }
}

Related

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