MD5StringUtil.java Source code

Java tutorial

Introduction

Here is the source code for MD5StringUtil.java

Source

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5StringUtil {
    private static final MessageDigest digest = MessageDigest.getInstance("MD5");

    public static String md5StringFor(String s) {
        final byte[] hash = digest.digest(s.getBytes());
        final StringBuilder builder = new StringBuilder();
        for (byte b : hash) {
            builder.append(Integer.toString(b & 0xFF, 16));
        }
        return builder.toString();
    }
}