package org.jboss.teiid.sizing.client;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Date;

public class MD5Encrypt {
	
	private String ping;
	
	private final MessageDigest md5;
	
	public MD5Encrypt(String ping) {
		this.ping = ping;
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException("No MD5 Algorithm Exist", e);
		}
	} 
	
	public String generatePassCode() {
		String token = getToken();
		String encrypt = ping + token;
		md5.reset();
		md5.update(encrypt.getBytes(), 0, encrypt.length());
		return new BigInteger(1,md5.digest()).toString(16);
	}

	public String getToken() {
		long time = getTime(new Date());
		long token = time / (60 * 60 * 24 * 3);
		return String.valueOf(token);
	}
	
	public String getTimeStamp(Date date) {
		long stamp = getTime(date);
		return String.valueOf(stamp);
	}
	
	public String getTimeStamp(int year, int month, int date) {
		long stamp = getTime(year, month, date);
		return String.valueOf(stamp);
	}

	public long getTime(Date date) {
		return date.getTime() / 1000;
	}
	
	public long getTime(int year, int month, int date) {
		
		Calendar calendar = Calendar.getInstance();
		calendar.set(year, month, date);
		return getTime(calendar.getTime());
	}
}

@@ -1366,10 +1366,314 @@
 ());%0A%09%7D%0A
+%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09Calendar calendar = Calendar.getInstance();%0A%09%09calendar.set(2015, 1, 1);%0A%09%09Date start = calendar.getTime();%0A%09%09Date end = new Date();%0A%09%09String url = RestClientHelper.getURL(%22access.devgssci.devlab.phx1.redhat.com%22,start, end);%0A%09%09%0A%09%09System.out.println(url);%0A%09%7D%0A
 %7D%0A

add cookie test code