您的位置:首页 > 其它

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

2017-08-29 14:13 645 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐