我正在尝试在我的 Java 程序中使用 basic64 编码。
问题是当我使用时
new sun.misc.BASE64Encoder().encode("my string".getBytes())
我收到带有\n 和\r 的 Base 64 字符串。我不知道如何避免这种情况,因为当我在文本文件中写入该字符串时,我得到以下内容
xxxxxxxxxxxxxxxx
yyyy
其中下一行由\n 和\r 生成。
我尝试使用替换(“\n”,“\n”)和\r相同,但我想知道是否有更好的解决方案或额外的参数,我可以在Base64编码中使用(甚至其他编码方式。)
我更改了库并且它正在工作!
这就是区别
Apache Q0FTSCNTVUJJUiMzNWYwMjFiMC1kZWRjLTRmZjgtYjNjMS0wZDY0NmVkMjFmOGUjMjAzMzU1MzczMzY=
太阳 FWmsMAID7Ecbf8gUd0WIvKBjJNXhtMCbcKVDW0R4KXY/e1Do8lItqDN4NH/RiBdckoIMeFrncJ5X Fju7R0cX822I/lFSkLab
奇怪...我以为 Base64 是一个标准...
最佳答案
Why Developers Should Not Write Programs That Call 'sun' Packages
The sun.* packages are not part of the supported, public interface. A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
考虑this :
probably somthing like this:
import org.apache.commons.codec.binary.Base64;
关于Base64 编码中的 Java 特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389808/