Base64

Base64编码的作用:将参数中的url的转换编码,以便其能通过get的方式来传递。
如果不编码的话,整段url中会出现多个http://的问题

Jar包用的是 commons-codec


package tristan;

import org.apache.commons.codec.binary.Base64;


/** * BASE64加密解密 */
public class TestBase64 {

	public static void main(String[] args) throws Exception {
		String sourceURL = "Action=https://{HPSC_SITE}/portal/site/hpsc/template.PAGE/action.process/it/credits/purchased/?javax.portlet.action=true&javax.portlet.sync=b8f162741ddb85f9d1ad5e329505ee01&javax.portlet.tpst=a5ad10428fcf524489ca89fa7505ee01&javax.portlet.prp_a5ad10428fcf524489ca89fa7505ee01=wsrp-interactionState%3Daction%253Ddetails%26wsrp-navigationalState%3Daction%253DfilterSearchView&javax.portlet.begCacheTok=com.vignette.cachetoken&javax.portlet.endCacheTok=com.vignette.cachetoken";
        String afterEncode = new String(Base64.encodeBase64(sourceURL.getBytes("UTF-8")),"UTF-8");

        System.out.println(afterEncode);
        
        
        String afterDecode = new String(Base64.decodeBase64(afterEncode.getBytes("UTF-8")),"UTF-8");
        System.out.println(afterDecode);
	
	}
}

你可能感兴趣的:(base64)