不建議使用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);	
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章