Java Utililty Methods MD5 String

List of utility methods to do MD5 String

Description

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

Method

Stringmd5(String s)
md
try {
    return md5(s.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return "";
byte[]md5(String s)
Get the MD5 of a string

try {
    return MessageDigest.getInstance("MD5").digest(s.getBytes());
} catch (NoSuchAlgorithmException ex) {
    throw new IOException(ex);
Stringmd5(String s)
md
MessageDigest md = getMessageDigest("md5");
return bytes2HexString(md.digest(s.getBytes(StandardCharsets.UTF_8)));
byte[]md5(String sInput)
Equivalent to (JavaSE): MessageDigest.getInstance("MD5").digest(sInput.getBytes()); Source: http://www.anavi.org/article/107/
int nDigestLen = 16;
byte[] PlainText = sInput.getBytes();
byte[] encryptedText = new byte[nDigestLen];
MessageDigest Cipher;
Cipher = MessageDigest.getInstance("MD5");
Cipher.update(PlainText, 0, PlainText.length);
Cipher.digest(encryptedText, 0, nDigestLen);
return encryptedText;
...
Stringmd5(String source)
md
try {
    byte[] bytes = md5(source.getBytes("utf-8"));
    char str[] = new char[bytes.length * 2];
    int k = 0;
    for (int i = 0; i < bytes.length; i++) {
        byte byte0 = bytes[i];
        str[k++] = hexDigits[byte0 >>> 4 & 0xf];
        str[k++] = hexDigits[byte0 & 0xf];
...
Stringmd5(String source)
md
java.security.MessageDigest md;
md = java.security.MessageDigest.getInstance("MD5");
md.update(source.getBytes());
byte tmp[] = md.digest();
char str[] = new char[16 * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
    byte byte0 = tmp[i];
...
Stringmd5(String source)
md
char hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
    byte[] bytes = source.getBytes();
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(bytes);
    bytes = md.digest();
    int j = bytes.length;
    char[] chars = new char[j * 2];
...
Stringmd5(String source)
md
byte[] buffer = source.getBytes("UTF-8");
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(buffer);
byte[] temp = md5.digest();
StringBuffer stringBuffer = new StringBuffer();
for (byte b : temp) {
    stringBuffer.append(Integer.toHexString(b & 0xff));
return stringBuffer.toString();
Stringmd5(String source)
md
StringBuffer sb = new StringBuffer(32);
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    byte[] array = md.digest(source.getBytes("utf-8"));
    for (int i = 0; i < array.length; i++) {
        sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1, 3));
} catch (Exception e) {
...
Stringmd5(String source, int bit)
md
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(source.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
    i = b[offset];
    if (i < 0)
...