Java Utililty Methods MD5 Hash

List of utility methods to do MD5 Hash

Description

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

Method

Stringmd5Hash(byte[] bytes)
md Hash
if (bytes == null) {
    return null;
return md5Hash(new ByteArrayInputStream(bytes));
byte[]md5Hash(byte[] data)
md5Hash
MessageDigest md = MessageDigest.getInstance("MD5");
return md.digest(data);
byte[]md5Hash(byte[] data)
Returns the MD5 hash for the data passed.
MessageDigest md;
try {
    md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException x) {
    throw new RuntimeException("MISSING MANDATORY SECURITY DIGEST PROVIDER MD5: " + x.getMessage());
md.update(data);
return md.digest();
...
byte[]md5hash(byte[] input)
mdhash
try {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    return digest.digest(input);
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("Unknown algorithm: MD5");
byte[]md5Hash(byte[] key)
md Hash
try {
    return MessageDigest.getInstance("MD5").digest(key);
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
Stringmd5Hash(String algorithm, String input)
md Hash
String output = "";
MessageDigest md = null;
byte[] digest = null;
try {
    md = MessageDigest.getInstance(algorithm);
    md.update(input.getBytes());
    digest = md.digest();
} catch (NoSuchAlgorithmException e) {
...
Stringmd5Hash(String buf)
md Hash
try {
    return md5Hash(buf.getBytes(US_ASCII));
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
Stringmd5Hash(String content)
md Hash
byte[] bytesOfMessage = null;
byte[] theDigest = null;
try {
    bytesOfMessage = content.getBytes("UTF-8");
    MessageDigest md = MessageDigest.getInstance("MD5");
    theDigest = md.digest(bytesOfMessage);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
...
Stringmd5Hash(String in)
md Hash
byte[] bytesOfMessage = null;
try {
    bytesOfMessage = in.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
    e1.printStackTrace();
MessageDigest md = null;
try {
...
Stringmd5Hash(String input)
md Hash
if (_md5Digest == null) {
    try {
        _md5Digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
byte[] digest = _md5Digest.digest(input.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
    sb.append(String.format("%02x", b));
return sb.toString();