两种不同的BASE 64 EN codeD字符串可能会导致成相同的字符串,如果去codeD? [英] Can two different BASE 64 encoded strings result into same string if decoded?

查看:147
本文介绍了两种不同的BASE 64 EN codeD字符串可能会导致成相同的字符串,如果去codeD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在客户端上我做的一个字符串的MD5加密,然后生成散列​​基地64编码。

On client side I am doing an MD5 encryption of a string and then a BASE 64 encoding on the hash generated.

这最终连接codeD的字符串是用于在服务器端进行比较。

This final encoded string is then used for comparison on server side.

我能够为许多测试用例成功地做到这一点,但它失败了下面的一个。

I was able to do this successfully for many test cases but it failed for the below one.

对于字符串的MD5

  2679:07071960:09348448:3:08912206:3:EXPRESS:1:EU4NW31E7INEC1X

我的MD5哈希字符串:

My MD5 hash string:

  291423A531148527A9524EA0924CDF68

我的Base64 EN codeD字符串:

My Base64 encoded string:

  KRQjpTEUhSepUk6gkkzfaA==

当我尝试把对BASE64编码MD5散列串在 HTTP: //www.opinionatedgeek.com/dotnet/tool​​s/base64en$c$c/ 的它生成以下字符串:

When I try to put the MD5 hash string for BASE64 encoding on http://www.opinionatedgeek.com/dotnet/tools/base64encode/ it generates following string:

  MjkxNDIzQTUzMTE0ODUyN0E5NTI0RUEwOTI0Q0RGNjg=

但是,当我尝试去code我Base64编码字符串,那就是KRQjpTEUhSepUk6gkkzfaA ==,这里的 http://www.opinionatedgeek.com/dotnet/tool​​s/Base64De$c$c/Default.aspx 我得到我的哈希code(开在十六进制编辑器生成.bin文件)。

But, when I try to decode my Base64 string, that is "KRQjpTEUhSepUk6gkkzfaA==", here http://www.opinionatedgeek.com/dotnet/tools/Base64Decode/Default.aspx I am getting my Hash Code(opened the .bin file being generated in hex editor).

那么,是有可能,一个字符串可以有多个连接的Base64 codeD值?

So, is it possible that a single string may have multiple Base64 encoded value?

我使用的是低于code产生的EN codeD字符串:

I am using the below code for generating the encoded string:

  public static String getHashCode(String text) 
 { 
    MessageDigest md;
    byte[] md5hash = new byte[32];
    try{
    md = MessageDigest.getInstance("MD5");

    md.update(text.getBytes("iso-8859-1"), 0, text.length());
    md5hash = md.digest();
    }
    catch(Exception e)
    {
        return "-1";
        }
    String encoded = Base64.encode(md5hash);
    String retValue = new String(encoded);


    return retValue;

   } 

请,建议什么错误,以及如何确保我们使用相同的客户端和服务器端都消化

Kindly, suggest what is going wrong and how to make sure that we use same digest both on client and server side.

推荐答案

您有MD5哈希291423A531148527A9524EA0924CDF68生成中的Base64 EN codeD字符串MjkxNDIzQTUzMTE0ODUyN0E5NTI0RUEwOTI0Q0RGNjg =,这是罚款。你已经转换的MD5哈希为ASCII十六进制重新presentation和Base64 EN codeD的。

You have the MD5 Hash 291423A531148527A9524EA0924CDF68 that generates the Base64 encoded string MjkxNDIzQTUzMTE0ODUyN0E5NTI0RUEwOTI0Q0RGNjg= , which is fine. You have converted the MD5 hash to an ascii hex representation, and base64 encoded that.

不过自己getHash code()的工作方式不同,它创建的二进制的再$ P $您的哈希code的psentation,你有没有转换你的哈希的base64编码一个十六进制ASCII重新presentation,这就是为什么你看到不同的base64 EN codeD字符串。

However your own getHashCode() works differently, it creates a base64 encoding of the binary representation of your hash code, you have not converted your hash to an ascii hex representation, and that's why you see different base64 encoded strings.

这篇关于两种不同的BASE 64 EN codeD字符串可能会导致成相同的字符串,如果去codeD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆