Java Base64编码的特殊字符
Java Special Characters in Base64 encode
我正在尝试在我的 Java 程序中使用 basic64 编码。
问题是当我使用
new sun.misc.BASE64Encoder().encode("my string".getBytes())
我收到带有 \n 和 \r 的 base 64 字符串。我不知道如何避免这种情况,因为当我在文本文件中写入该字符串时,我得到以下内容
xxxxxxxxxxxxxxxx
yyyy
下一行由 \n 和 \r 生成。
我尝试使用 replace("\n","\n") 和相同的 \r 但我想知道是否有更好的解决方案或我可以在 Base64 编码中使用的额外参数 (甚至其他编码方式。)
我更改了库,它正在运行!
区别在这里
阿帕奇
Q0FTSCNTVUJJUiMzNWYwMjFiMC1kZWRjLTRmZjgtYjNjMS0wZDY0NmVkMjFmOGUjMjAzMzU1MzczMzY=
太阳
FWmsMAID7Ecbf8gUd0WIvKBjJNXhtMCbcKVDW0R4KXY/e1Do8lItqDN4NH/RiBdckoIMeFrncJ5X
Fju7R0cX822I/lFSkLab
奇怪...我以为Base64是标准...
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;
我正在尝试在我的 Java 程序中使用 basic64 编码。
问题是当我使用
new sun.misc.BASE64Encoder().encode("my string".getBytes())
我收到带有 \n 和 \r 的 base 64 字符串。我不知道如何避免这种情况,因为当我在文本文件中写入该字符串时,我得到以下内容
xxxxxxxxxxxxxxxx
yyyy
下一行由 \n 和 \r 生成。
我尝试使用 replace("\n","\n") 和相同的 \r 但我想知道是否有更好的解决方案或我可以在 Base64 编码中使用的额外参数 (甚至其他编码方式。)
我更改了库,它正在运行!
区别在这里
阿帕奇 Q0FTSCNTVUJJUiMzNWYwMjFiMC1kZWRjLTRmZjgtYjNjMS0wZDY0NmVkMjFmOGUjMjAzMzU1MzczMzY=
太阳 FWmsMAID7Ecbf8gUd0WIvKBjJNXhtMCbcKVDW0R4KXY/e1Do8lItqDN4NH/RiBdckoIMeFrncJ5X Fju7R0cX822I/lFSkLab
奇怪...我以为Base64是标准...
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;