base64解码,使用utf-8、utf-16输出不正确

pbossiut  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(317)

我已经在我的电脑上建立了本地restapi服务器,我有注册功能,发送用户数据到mysql数据库。
我已经将密码字符串编码为base64字符串(想尝试加密我自己)。当我试图解码我从数据库获取的密码时,我得到了错误的输出。
密码示例(base64):mdq1mta0nte=
输出-04510451
解码器类-

byte[] decodedValue = Base64.getDecoder().decode(password);  

return new String(decodedValue, StandardCharsets.UTF_8);

编码器类-

byte[] passEncoded = Base64.getEncoder().encode(password.getBytes("UTF-8"));
System.out.println("encoded value is " + new String(passEncoded));
String finalPass = null;
finalPass = new String(passEncoded, "UTF-8");

return finalPass;

现在我得到的实际输出是:“ӎuӎu“(需要是04510451)
谢谢你,乔纳森

kwvwclae

kwvwclae1#

看起来你解码了两次。这在您提供的代码片段中是不可见的,但却是最符合逻辑的解释: MDQ1MTA0NTE= -> 04510451 -> ӎuӎu

相关问题