Java Utililty Methods MD5

List of utility methods to do MD5

Description

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

Method

intmd5_hh(int C, int B, int G, int F, int A, int E, int D)
mhh
return md5_cmn(B ^ G ^ F, C, B, A, E, D);
Stringmd5_id(byte[] md5digest)
mid
StringBuilder hashbuf = new StringBuilder(md5digest.length * 2);
for (byte b : md5digest) {
    int intVal = b & 0xff;
    if (intVal < 0x10) {
        hashbuf.append("0");
    hashbuf.append(Integer.toHexString(intVal));
return hashbuf.toString().toLowerCase();
Stringmd5bytesToHex(byte[] md5)
mdbytes To Hex
StringBuilder sb = new StringBuilder();
for (byte aMd5 : md5) {
    sb.append(Integer.toString((aMd5 & 0xff) + 0x100, 16).substring(1));
return sb.toString();
Stringmd5Encode(byte[] content)
md Encode
return DatatypeConverter.printBase64Binary(content);
Stringmd5Encode(String strIn)
Compute the MD5 of the given string and return it as a Base64-encoded value.
try {
    MessageDigest md5 = MessageDigest.getInstance("md5");
    byte[] bin = toBytes(strIn);
    byte[] bout = md5.digest(bin);
    String strOut = javax.xml.bind.DatatypeConverter.printBase64Binary(bout);
    return strOut;
} catch (Exception e) {
    throw new RuntimeException(e.getMessage(), e);
...
Stringmd5HashByteToString(byte[] bytes)
Creates an MD5 string from the given bytes.
String result = "";
for (int i = 0; i < bytes.length; i++) {
    result += Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1);
return result;
byte[]md5HashStringToByte(String hash)
Creates an MD5 byte array from the given MD5 hash.
byte[] buf = new byte[16];
int i = 0;
while (hash.length() > 0) {
    buf[i++] = (byte) Integer.parseInt(hash.substring(0, 2), 16);
    hash = hash.substring(2);
return buf;
Stringmd5Hex(final String text)
md Hex
try {
    final byte[] bytesOfMessage = text.getBytes("UTF-8");
    final MessageDigest md = MessageDigest.getInstance("MD5");
    final byte[] digest = md.digest(bytesOfMessage);
    return DatatypeConverter.printHexBinary(digest).toLowerCase();
} catch (Exception e) {
    throw new RuntimeException();
voidmd5Init()
md Init
count[0] = 0L;
count[1] = 0L;
state[0] = 0x67452301L;
state[1] = 0xefcdab89L;
state[2] = 0x98badcfeL;
state[3] = 0x10325476L;
return;
voidmd5Memcpy(byte[] output, byte[] input, int outpos, int inpos, int len)
md Memcpy
int i;
for (i = 0; i < len; i++)
    output[outpos + i] = input[inpos + i];