Base64 解码返回垃圾
我正在尝试从 Java 中的身份验证标头中解码 Base64 字符串。我确信发送的请求在身份验证标头中具有有效的 Base64 编码字符串。这是我的解码代码:
HttpServletRequest request = (HttpServletRequest) req;
byte[] test = new Base64().decode(request.getHeader("Authorization"));
在解码请求之前,它看起来像这样 Basic dXNlcjpmZGdmcw==
在我尝试解码它之后,它看起来像这样: «"qÕÍ•Èé™'™Ì< /code>
我不确定我做错了什么,无论我使用什么解码实用程序,它总是看起来像乱码,感谢您的阅读。
I am trying to decode a Base64 string from my authentication headers in Java. I am certain that the request being sent has a valid Base64 encoded string in the authentication header. Here is my decoding code:
HttpServletRequest request = (HttpServletRequest) req;
byte[] test = new Base64().decode(request.getHeader("Authorization"));
Before I decode the request it looks like this Basic dXNlcjpmZGdmcw==
After I try to decode it it looks like this: «"qÕÍ•È陑™Ì
I am not sure what I am doing wrong, and no matter what decode utility I use it always ends up looking like gibberish. Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
打印
user:fdgfs
。注意:在 Java 中解码 Base64 数据以获得更好的解决方案。您是否检查过返回的内容:?
Prints
user:fdgfs
. Note: Decode Base64 data in Java for better solutions. Have you checked what is returned by:?
那是因为您试图解码整个字符串“Basic dXNlcjpmZGdmcw==”而不是
“dXNlcjpmZGdmcw==”。
Thats because you are trying to decode whole String "Basic dXNlcjpmZGdmcw==" instead of
"dXNlcjpmZGdmcw==".