Project

General

Profile

1
package eu.dnetlib.utils.md5;
2

    
3
import java.math.BigInteger;
4
import java.security.MessageDigest;
5
import java.security.NoSuchAlgorithmException;
6

    
7
public class MD5 {
8

    
9
	public MD5() {
10
	}
11

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

    
19
	static public String encrypt2Hex(String input)
20
			throws NoSuchAlgorithmException {
21

    
22
		return Integer.toHexString(encrypt(input));
23
	}
24

    
25
	public static void main(String[] args) throws NoSuchAlgorithmException {
26
		System.out.println(MD5.encrypt2Hex("password"));
27
	}
28
}
    (1-1/1)