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