跟着老师一起敲打的,感觉还是很神奇哦!!!
注意啦:sun.misc.BASE64Encoder找不到jar包的解决方法
1.右键项目-》属性-》Java bulid path-》jre System Library-》access rules-》resolution选择accessible,下面填上** 点击确定即可!!!
2.
在MyEclipse中编写Java代码时,用到了BASE64Decoder,import sun.misc.BASE64Decoder;可是Eclipse提示:
Access restriction: The type BASE64Decoder is not accessible due to restriction on required library C:\Program
files\java\jre6\lib\rt.jar
Access restriction : The constructor BASE64Decoder() is not accessible due to restriction on required library C:\Program files\java\jre6\lib\rt.jar
解决方案1(推荐):
只需要在project build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了。
解决方案2:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings ->
Deprecated and trstricted API -> Forbidden reference (access rules): -> change to warning
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jcajce.provider.symmetric.ARC4.Base;
import org.bouncycastle.util.encoders.Base64Encoder;
import sun.security.*;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
public class loveBase64 {
private static String class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="immoc security base64";
public static void main(String[] args) {
// TODO Auto-generated method stub
//jdkbase64();
//commonsCodesBase64();
bouncyCastleBase64();
}
public static void jdkbase64(){
try {
BASE64Encoder encoder=new BASE64Encoder();
String encode=encoder.encode(src.getBytes());
System.out.println("encode:"+encode);
BASE64Decoder decoder=new BASE64Decoder();
System.out.println("decode:"+new String(decoder.decodeBuffer(encode)));
} catch (IOException e) {
// TODO: handle exception
}
}
public static void commonsCodesBase64(){
byte[] encodeBytes=Base64.encodeBase64(src.getBytes());
System.out.println("encode:"+new String(encodeBytes));
byte[] decodeBytes=Base64.decodeBase64(encodeBytes);
System.out.println("decode:"+new String(decodeBytes));
}
public static void bouncyCastleBase64(){
byte[] encodeBytes=org.bouncycastle.util.encoders.Base64.encode(src.getBytes());
System.out.println("encode:"+new String(encodeBytes));
byte[] decodeBytes=org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
System.out.println("decode:"+new String(decodeBytes));
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章