String s="http://localhost:9080/wxpaytest/OAuthForWard.jsp";
//使用base64进行加密
sun.misc.BASE64Encoder base=new sun.misc.BASE64Encoder();
//指定utf-8编码
byte[] bytes = s.getBytes("utf-8");
//对数组进行加密
String encode = base.encode(bytes);
//加密后 得到:aHR0cDovL2xvY2FsaG9zdDo5MDgwL3d4cGF5dGVzdC9PQXV0aEZvcldhcmQuanNw
System.out.println(encode+"\n"+encode.length());
-----------------------对encode进行解密
//进行解密
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
byte[] buffer = decoder.decodeBuffer(encode);
//指定utf-8解码
System.out.println(new String(buffer,"utf-8"));
学者: kangSir
java使用BASE64进行字符串数据加密和解密
最新推荐文章于 2024-07-29 03:27:34 发布