import org.apache.commons.codec.binary.Base64;
public class EncodingUtility {
	/**
	 * to encode data as base64
	 * @param string
	 * @return encodedDataasBase64
	 * @throws Exception
	 */
	public static String encodeStringAsBase64(String string) throws Exception{
		String hex = "";
		try {
			Base64 b64 = new Base64();
			hex = new String( b64.encode( string.getBytes() ) );
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return hex;
	}

	/**
	 * to decode data as base64 to original form
	 * @param string
	 * @return decodeDataasBase64
	 * @throws Exception
	 */
	public static String decodeStringAsBase64(String string) throws Exception{
		String hex = "";
		try {
			Base64 b64 = new Base64();
			hex = new String( b64.decode( string.getBytes() )) ;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return hex;
	}
}
