Java Utililty Methods MD5 String

List of utility methods to do MD5 String

Description

The list of methods to do MD5 String are organized into topic(s).

Method

Stringmd5(String string)
md
try {
    return bytesToHex(MessageDigest.getInstance("md5").digest(string.getBytes("UTF-8")));
} catch (Exception e) {
    return string;
Stringmd5(String string)
md
byte[] hash;
try {
    hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Huh, MD5 should be supported?", e);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Huh, UTF-8 should be supported?", e);
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
    if ((b & 0xFF) < 0x10)
        hex.append("0");
    hex.append(Integer.toHexString(b & 0xFF));
return hex.toString();
Stringmd5(String strs)
md
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;
try {
    md = MessageDigest.getInstance("MD5");
    md.update(source);
    byte tmp[] = md.digest();
...
Stringmd5(String target)
MD5
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(target.getBytes("utf-8"));
byte[] md5Bytes = digest.digest();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < md5Bytes.length; i++) {
    sb.append(Character.forDigit(md5Bytes[i] >>> 4 & 0xf, 16));
    sb.append(Character.forDigit(md5Bytes[i] & 0xf, 16));
return sb.toString();
StringMD5(String text)
MD
MessageDigest md;
try {
    md = MessageDigest.getInstance(MD5);
    byte[] md5hash = new byte[32];
    md.update(text.getBytes(ISO_8859_1), 0, text.length());
    md5hash = md.digest();
    return convertToHex(md5hash);
} catch (NoSuchAlgorithmException e1) {
...
Stringmd5(String text)
md
return md5(text.getBytes("UTF-8"));
StringMD5(String text)
Returns text digested in MD5.
MessageDigest md5 = null;
try {
    md5 = MessageDigest.getInstance("MD5");
} catch (Exception e) {
    System.out.println("***** MD5 EXC: " + e);
md5.update(text.getBytes());
return toHexString(md5.digest());
...
Stringmd5(String text)
md
MessageDigest msgDigest = null;
try {
    msgDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException("System doesn't support MD5 algorithm.");
try {
    msgDigest.update(text.getBytes("UTF-8"));
...
Stringmd5(String text)
md
if (isNullOrEmpty(text))
    return "";
StringBuffer hexString = new StringBuffer();
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(text.getBytes());
    byte[] digest = md.digest();
    for (int i = 0; i < digest.length; i++) {
...
Stringmd5(String text)
md
MessageDigest md = null;
String outStr = null;
try {
    md = MessageDigest.getInstance("MD5");
    byte[] digest = md.digest(text.getBytes());
    outStr = bytes2hex(digest);
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
...