欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Base64加密解密实例

程序员文章站 2022-03-12 19:40:03
...
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);
	}
	
}

相关标签: 代码