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

Stringmd5ToHex(byte[] hash)
md To Hex
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
    String hex = Integer.toHexString(0xFF & b);
    if (hex.length() == 1) {
        hexString.append('0');
    hexString.append(hex);
return hexString.toString();
Stringmd5ToString(byte[] md5sum)
md To String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < md5sum.length; i++) {
    sb.append(Integer.toString((md5sum[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
voidmd5Update(byte[] inbuf, int inputLen)
md Update
int i, index, partLen;
byte[] block = new byte[64];
index = (int) (count[0] >>> 3) & 0x3F;
if ((count[0] += (inputLen << 3)) < (inputLen << 3))
    count[1]++;
count[1] += (inputLen >>> 29);
partLen = 64 - index;
if (inputLen >= partLen) {
...
MessageDigestnewMd5()
new Md
try {
    return MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException ex) {
    return null;
StringnewMD5HashUri(String value)
new MD Hash Uri
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    byte[] asBytes;
    try {
        asBytes = value.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new IllegalStateException("unexpected", e);
...
MessageDigestnewMd5MessageDigest()
new Md Message Digest
MessageDigest md;
try {
    md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Required MD5 message digest algorithm unavailable.");
md.reset();
return md;
...
booleanvalidateMD5(String md5String)
Returns true if the String could be a md5
if (md5String == null) {
    throw new IllegalArgumentException("md5String is null");
return md5String.length() == 32 && md5String.matches("([a-z0-9])+");