import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author BABUKUMA
*/
public final class Digest {
public static byte[] md5(final String data) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] dat = data.getBytes();
md.update(dat);
return md.digest();
}
// MD5 ハッシュ関数
private static String hashByte2MD5(byte[] hash) {
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
if ((0xff & b) < 0x10) {
hexString.append("0" + Integer.toHexString((0xFF & b)));
} else {
hexString.append(Integer.toHexString(0xFF & b));
}
}
return hexString.toString();
}
public static String md5String(final String data)
throws NoSuchAlgorithmException {
return hashByte2MD5(md5(data));
}
}