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

StringdigestMD5(String text)
Calculate the MD5 digest code for the text.
return digest(text, "MD5");
Stringencryptmd5(String str)
encryptmd
char[] a = str.toCharArray();
for (int i = 0; i < a.length; i++) {
    a[i] = (char) (a[i] ^ 'l');
String s = new String(a);
return s;
StringgenerateMD5ByContent(String content)
generate MD By Content
return "";
StringgetFileMD5(String filePath)
get File MD
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(Files.readAllBytes(Paths.get(filePath)));
    byte[] digest = md.digest();
    return DatatypeConverter.printHexBinary(digest).toLowerCase();
} catch (Exception e) {
    e.printStackTrace();
return null;
StringgetHexMd5(byte[] bytes)
Get a hex representation of the MD5 checksum of an array of bytes.
MessageDigest digest = null;
try {
    digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
digest.update(bytes);
String md5 = DatatypeConverter.printHexBinary(digest.digest()).toLowerCase();
return md5;
...
StringgetMD5(File file)
Get the MD5 Hash from the given File.
String path = file.getAbsolutePath();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(Files.readAllBytes(Paths.get(path)));
return DatatypeConverter.printHexBinary(md.digest()).toUpperCase();
StringgetMD5ByString(String orginalString)
get MD By String
return orginalString;
StringgetMD5Checksum(String path)
get MD Checksum
return null;
StringgetMd5DigestHex(final String content)
get Md Digest Hex
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(content.getBytes());
return DatatypeConverter.printHexBinary(digest);
StringgetMD5Hex(byte[] digest)
get MD Hex
StringBuilder result = new StringBuilder();
for (byte b : digest) {
    String hexString = Integer.toHexString(b & 0xff);
    if (hexString.length() == 1) {
        result.append("0");
    result.append(hexString);
return result.toString();