All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.hajdbc.util.MD5 Maven / Gradle / Ivy

There is a newer version: 3.6.61
Show newest version
package net.sf.hajdbc.util;

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

public final class MD5 {
  private static final String MD5_NAME = "MD5";

  private MD5() {
  }

  public static MessageDigest newInstance() {
    try {
      return MessageDigest.getInstance(MD5_NAME);
    } catch (NoSuchAlgorithmException e) {
      throw new RuntimeException(e);              // support for MD5 is required so this should not happen
    }
  }

  public static String md5DigestToString(byte[] digestBuf) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < digestBuf.length; i++) {
      sb.append(Integer.toHexString(0xFF & digestBuf[i]));
    }
    return sb.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy