利用 BASE64Encoder 对字符串进行加密 BASE64Decoder进行解密

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class TestEncrypt {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s="http://localhost:9080/wxpaytest/OAuthForWard.jsp";
		
		System.out.println(base64Encoder(s));
		System.out.println(base64Decoder("aHR0cDovL2xvY2FsaG9zdDo5MDgwL3d4cGF5dGVzdC9PQXV0aEZvcldhcmQuanNw"));
	}
	
	public static String base64Encoder(String str){
		
		 BASE64Encoder encode = new BASE64Encoder();
		 return encode.encode(str.getBytes());
		 
	}

	public static String base64Decoder(String str){
		
		 BASE64Decoder decode=new BASE64Decoder();
		 String result="";
		 
		 byte[] b;
			try {
				b = decode.decodeBuffer(str);
				result=new String(b);
				
			} catch (IOException e) {
				e.printStackTrace();
			}
		
			return result;
	}


}

你可能感兴趣的:(JAVA,HTML)