Base64加密解密实例

package testBase64;

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

public class TestBase64 {

	//加密
	public static void encoder(String params){
		String resqString = "";
		BASE64Encoder encoder = new BASE64Encoder();
		resqString = encoder.encode(params.getBytes());
		resqString = "param=" + resqString;
		System.out.println("param======="+resqString);
	}
	//解密
	public static void decoder(String response){
		byte[] respByte;
		BASE64Decoder encoder = new BASE64Decoder();
		try {
			respByte = encoder.decodeBuffer(response);
			String str = new String(respByte,"utf-8");
			System.out.println("str======="+str);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args){
		String param = "aaabbb";
		//String response = "YWFhYmJi";
		encoder(param);
		//decoder(response);
	}
	
}

猜你喜欢

转载自blog.csdn.net/fei18234037709/article/details/80682397