Android中Base64加密
转自:http://blog.csdn.net/z191726501/article/details/52778478CRLF:这个参数看起来比较眼熟,它就是Win风格的换行符,意思就是使用CR LF这一对作为一行的结尾而不是Unix风格的LFDEFAULT:这个参数是默认,使用默认的方法来加密NO_PADDING:这个参数是略去加密字符串最后的“=”NO_WRAP:这个参数意思是略去所有的换行符(设置后CRLF就没用了)URL_SAFE:这个参数意思是加密时不使用对URL和文件名有特殊意义的字符来作为加密字符,具体就是以-和_取代+和/
public class Base64Utils {// 加密 public static String getBase64(String str) { String result = ""; if( str != null) {try { result = new String(Base64.encode(str.getBytes("utf-8"), Base64.NO_WRAP),"utf-8");} catch (UnsupportedEncodingException e) { e.printStackTrace(); } }return result; } // 解密 public static String getFromBase64(String str) { String result = ""; if (str != null) { try {result = new String(Base64.decode(str, Base64.NO_WRAP), "utf-8");} catch (UnsupportedEncodingException e) {e.printStackTrace();} } return result; }
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
