您的位置:首页 > 其它

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

2016-06-16 20:07 453 查看
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class TestEncrypt {

public static void main(String[] args) {
// TODO Auto-generated method stub
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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: