Can two different BASE64 encoded strings result into same string if decoded?

后端 未结 2 947
刺人心
刺人心 2021-02-10 01:33

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

This final encoded string is then used for comparison on serve

相关标签:
2条回答
  • 2021-02-10 02:09

    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.

    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.

    0 讨论(0)
  • 2021-02-10 02:31

    The accepted answer solves the problem but does not answer the question.

    For example, these base64 values QzNWwq== and QzNWwr== encode the same binary value (hex) 433356c2

    You can check it at http://kjur.github.io/jsjws/tool_b64udec.html or using the command

    echo <<BASE64>> | base64 -d | xxd
    

    In summary

    • Two different base 64 encode same value --> true
    • Two different values generate the same base64 value --> false (see this)
    0 讨论(0)
提交回复
热议问题