不建议使用sun.misc.BASE64Encoder

最近在项目中用到sun.misc.BASE64Encoder包的BASE64Encoder对字符串进行编码,但是将编码后的字符串输出后发现字符串中存在换行符\r\n

google 原来“回车换行符(\r\n)”是在Windows才有,而Linux只有换行(\n),Mac只有回车(\r)。

建议使用import org.apache.commons.codec.binary.Base64;进行替换

import sun.misc.BASE64Encoder;

return new  BASE64Encoder().encode(encrypted);

替换为

import org.apache.commons.codec.binary.Base64;
return Base64.encodeBase64String(encrypted);

import sun.misc.BASE64Decoder;

byte[] encrypted1 = new BASE64Decoder().decodeBuffer(text);	

替换为

import org.apache.commons.codec.binary.Base64;
byte[] encrypted1 =Base64.decodeBase64(text);	
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章