最近在項目中用到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);