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


import java.io.IOException;

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

public class Test {

	public static void main(String[] args) {
		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;
	}

}

控制台输出:

aHR0cDovL2xvY2FsaG9zdDo5MDgwL3d4cGF5dGVzdC9PQXV0aEZvcldhcmQuanNw
http://localhost:9080/wxpaytest/OAuthForWard.jsp


点击打开链接网址:https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-8178633207.45.3ff19e118ulEyN&id=546912221341

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值