android自带Base64加密解密

android项目引用不到以下两个java类

 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;

android有自己的base64类

 import android.util.Base64

//import android.util.Base64;

String str = "Hello!";
//base64编码
//String strBase64 = new String(Base64.encode(str.getBytes(), Base64.DEFAULT));
String strBase64 = Base64.encodeToString(str.getBytes(), Base64.DEFAULT);
//base64解码
String str2 = new String(Base64.decode(strBase64.getBytes(), Base64.DEFAULT));

猜你喜欢

转载自happyqing.iteye.com/blog/2287679