Generate the MD5 hash out of the given {@link ByteBuffer}
768876
private static String md5(byte[] buffer) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(buffer);
            byte[] digest = md.digest();
            return new String(FlexBase64.encodeBytes(digest, 0, digest.length, false), StandardCharsets.US_ASCII);
        } catch (NoSuchAlgorithmException e) {
            // Should never happen
            throw new InternalError("MD5 not supported on this platform");
        }
    }
892244
public static byte[] computeMD5Hash(byte[] input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return md.digest(input);
        } catch (NoSuchAlgorithmException e) {
            // should never get here
            throw new IllegalStateException(e);
        }
    }
112863
function MD5_encode(source) { // @arg Uint8Array
                              // @ret Uint8Array
//{@dev
    $valid($type(source, "Uint8Array"), MD5_encode, "source");
//}@dev

    var buffer = _createBufferWith64BytePadding(source);
    var hash   = _MD5(buffer); // [a, b, c, d]
    var result = new Uint8Array(16);

    for (var ri = 0, hi = 0; hi < 4; ri += 4, ++hi) {
        result[ri    ] = hash[hi]        & 0xff;
        result[ri + 1] = hash[hi] >>>  8 & 0xff;
        result[ri + 2] = hash[hi] >>> 16 & 0xff;
        result[ri + 3] = hash[hi] >>> 24 & 0xff;
    }
    return result;
}
476725
public static InputStream byteBufferToInputStream(final ByteBuffer byteBuffer) {
        // https://stackoverflow.com/questions/4332264/wrapping-a-bytebuffer-with-an-inputstream/6603018#6603018
        return new InputStream() {
            /** The intermediate buffer. */
            final ByteBuffer buf = byteBuffer;

            @Override
            public int read() {
                if (!buf.hasRemaining()) {
                    return -1;
                }
                return buf.get() & 0xFF;
            }

            @Override
            public int read(final byte[] bytes, final int off, final int len) {
                if (!buf.hasRemaining()) {
                    return -1;
                }

                final int bytesRead = Math.min(len, buf.remaining());
                buf.get(bytes, off, bytesRead);
                return bytesRead;
            }
        };
    }
906115
public static String generateMD5(final String input) {
        try {
            return generateMD5(input.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            LOG.debug("An error occurred generating the MD5 Hash of the input string", e);
            return null;
        }
    }
1246275
public static MD5Digest fromBytes(byte[] md5Bytes, int offset) {
    byte[] md5BytesCopy = Arrays.copyOfRange(md5Bytes, offset, offset + MD5_BYTES_LENGTH);
    //TODO: Replace this with a version that encodes without needing a copy.
    String md5String = Hex.encodeHexString(md5BytesCopy);
    return new MD5Digest(md5String, md5BytesCopy);
  }
197259
public static String md5(byte[] data, byte[] salt) {
        if (data == null || salt == null) return null;
        byte[] dataSalt = new byte[data.length + salt.length];
        System.arraycopy(data, 0, dataSalt, 0, data.length);
        System.arraycopy(salt, 0, dataSalt, data.length, salt.length);
        return bytes2HexString(md5ToByte(dataSalt));
    }
852322
public static MD5Hash digest(byte[] data, int start, int len) {
    byte[] digest;
    MessageDigest digester = DIGESTER_FACTORY.get();
    digester.update(data, start, len);
    digest = digester.digest();
    return new MD5Hash(digest);
  }
750185
def _md5(path, blocksize=2 ** 20):
    """"""
    m = hashlib.md5()
    with open(path, 'rb') as f:
        while True:
            buf = f.read(blocksize)
            if not buf:
                break
            m.update(buf)
    return m.hexdigest()
448879
function md5(data, digest) {
            var hash = "";

            if (!digest) { digest = 'binary'; }

            if (digest === 'buffer') {
                digest = undefined;
                // todo: 不支持 buffer 类型的 hash
                return "";
            }

            if (typeof data === 'string') {
                switch (digest) {
                    case "binary":
                        return SparkMD5.hash(data, true);
                    case "hex":
                        return SparkMD5.hash(data);
                    case "base64":
                        return TableStore.util.hexToBase64(SparkMD5.hash(data));
                    default:
                        return "";
                }
            }
            else {  // array buffer
                switch (digest) {
                    case "binary":
                        return SparkMD5.ArrayBuffer.hash(data, true);
                    case "hex":
                        return SparkMD5.ArrayBuffer.hash(data);
                    case "base64":
                        return TableStore.util.hexToBase64(SparkMD5.ArrayBuffer.hash(data));
                    default:
                        return "";
                }
            }
        }
234559
public static String toMD5hash(final String s) {

        String hash = null;
        if (null != s) {
            try {
                final MessageDigest digest = MessageDigest.getInstance("MD5");
                digest.update(s.getBytes(Charset.forName("utf-8")));
                final byte[] md5sum = digest.digest();
                final BigInteger bigInt = new BigInteger(1, md5sum);
                hash = bigInt.toString(16);
            } catch (final NoSuchAlgorithmException e) {
                throw new RuntimeException("MD5 digest algorithm implementation not found", e);
            }
        }
        return hash;
    }
171489
public static String calculateMD5(String string) {
		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) {
			int i = (b & 0xFF);
			if (i < 0x10)
				hex.append('0');
			hex.append(Integer.toHexString(i));
		}

		return hex.toString();
	}
708167
public static byte[] md5Bytes(String str) {
        if (str == null) return null;
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
        return md5.digest(str.getBytes());
    }
643170
public static byte[] md5Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return md5Hash(data.getBytes(charset));
	}
882802
public static String MD5Encode(String origin) {
		String resultString = null;
		try {
			resultString = origin;
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(resultString.getBytes("UTF-8"));
			resultString = byteArrayToHexString(md.digest());
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return resultString;
	}
440450
public final int hash(ByteBuffer buf, int seed) {
    final int hash = hash(buf, buf.position(), buf.remaining(), seed);
    buf.position(buf.limit());
    return hash;
  }
290405
public static MD5Digest fromBytes(byte[] md5Bytes)
  {
    Preconditions.checkArgument(md5Bytes.length == MD5_BYTES_LENGTH,
        "md5 bytes must be " + MD5_BYTES_LENGTH + " bytes in length, found " + md5Bytes.length + " bytes.");
    String md5String = Hex.encodeHexString(md5Bytes);
    return new MD5Digest(md5String, md5Bytes);
  }