package eu.dnetlib.utils.md5;

import java.security.*;
import java.math.*;

public class MD5 {

	public MD5() {
	}

	static public int encrypt(String input) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(input.getBytes());// transforms password into md5 hash
		BigInteger hash = new BigInteger(1, md.digest());
		return hash.intValue();
	}

	static public String encrypt2Hex(String input)
			throws NoSuchAlgorithmException {

		return Integer.toHexString(encrypt(input));
	}

	public static void main(String[] args) throws NoSuchAlgorithmException {
		System.out.println(MD5.encrypt2Hex("password"));
	}
}