在 Java 中从 Base 64 字符串转换
有没有办法像在 .NET 中使用 Java 一样转换 Base64 字符串?我怎样才能实现这个目标?
这是 .NET 示例:
Convert.FromBase64String
Is there any way to convert a Base64 String like you can in .NET using Java? How can I achieve this?
Here is the .NET example :
Convert.FromBase64String
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我觉得奇怪的是,每次有人询问 Java 中的 Base 64 编码/解码时,给出的唯一答案要么使用 Apache 编解码器库,要么使用不应该使用的旧 com.sun 类,或者假设它在应用程序服务器中比如Tomcat提供的。
自从在 javax.xml.bind.DatatypeConverter 类中引入 Jaxb 1.0 以来,标准 JDK 就提供了 Base 64 支持。
因此,如果您使用的是 Java 6 或更高版本(当 Jaxb1.0 直接添加到 JDK 时,在此之前可以作为参考使用),您不需要使用第 3 方组件来支持 Base 64,您可以使用内置于 JDK 中。
I find it curious that every time someone asks about base 64 encoding/decoding in Java the only answers given are either use the Apache codecs library, use the old com.sun classes which shouldn't be used or assume it is in the application server such as the one provided by Tomcat.
The standard JDK has provided base 64 support since the introduction of Jaxb 1.0 in the javax.xml.bind.DatatypeConverter class.
So if you are using Java 6 or newer (when Jaxb1.0 was added to the JDK directly, was available as a ref prior to that) you don't need to use a 3rd party component for base 64 support, you can use what is built into the JDK.
byte[] returnedBytes = Base64.decode(base64Message);
字符串解码字符串=新字符串(decodedBytes);
byte[] decodedBytes = Base64.decode(base64Message);
String decodedString = new String(decodedBytes);
我想你想解码一个base64编码的字符串...你可以使用这个..
I think you want to decode a base64encoded String...you can use this..