MD5 MessageDigest : MD5 « Security « Java

MD5 MessageDigest

 * file
 * This file is part of SourceHeader project.
 * SourceHeader is software for easier maintaining source files' headers.
 * project web:
 * author: Steve Sindelar
 * licence: New BSD Licence
 * (c) Steve Sindelar

//package sourceheader.core.util;


 * @author steve
public class MD5 {
  public static String create(String content) throws MD5IsNotSupported {
    String result = "";
    try {
      byte[] defaultBytes = content.getBytes();
      MessageDigest algorithm = MessageDigest.getInstance("MD5");
      byte messageDigest[] = algorithm.digest();

      StringBuffer hexString = new StringBuffer();
      for (int i = 0; i < messageDigest.length; i++) {
        hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
      result = hexString.toString();
    } catch (NoSuchAlgorithmException ex) {
      throw new MD5IsNotSupported(ex);

    assert !result.isEmpty();
    return result;

  public static class MD5IsNotSupported extends NoSuchAlgorithmException {
    public MD5IsNotSupported(Throwable exception) {
      super("MD5 algorithm is not implemented in this java.", exception);


Related examples in the same category

1.OTP one-time password calculationOTP one-time password calculation
2.Applet to serve as an s/key calculator application wrapper around otp class
3.Creating a Keyed Digest Using MD5
4.MD5 BASE64 checksum for the specified input string.
5.MD5 InputStream
6.Implements MD5 functionality on a stream.
7.Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher
8.MD5 algorithm RFC 1321
9.Contains internal state of the MD5 class
10.Create MD5 String
11.MD5 string
12.MD5 Sum
13.MD5 Hashing utility that builds up a hash from a series of objects and base types fed into it.
14.Get MD5 string