Note that there are some explanatory texts on larger screens.

plurals
  1. POCan two different BASE 64 encoded strings result into same string if decoded?
    text
    copied!<p>On client side I am doing an MD5 encryption of a string and then a BASE 64 encoding on the hash generated.</p> <p>This final encoded string is then used for comparison on server side.</p> <p>I was able to do this successfully for many test cases but it failed for the below one.</p> <p>String for MD5</p> <pre><code> 2679:07071960:09348448:3:08912206:3:EXPRESS:1:EU4NW31E7INEC1X </code></pre> <p>My MD5 hash string:</p> <pre><code> 291423A531148527A9524EA0924CDF68 </code></pre> <p>My Base64 encoded string:</p> <pre><code> KRQjpTEUhSepUk6gkkzfaA== </code></pre> <p>When I try to put the MD5 hash string for BASE64 encoding on <a href="http://www.opinionatedgeek.com/dotnet/tools/base64encode/" rel="noreferrer">http://www.opinionatedgeek.com/dotnet/tools/base64encode/</a> it generates following string:</p> <pre><code> MjkxNDIzQTUzMTE0ODUyN0E5NTI0RUEwOTI0Q0RGNjg= </code></pre> <p>But, when I try to decode my Base64 string, that is "KRQjpTEUhSepUk6gkkzfaA==", here <a href="http://www.opinionatedgeek.com/dotnet/tools/Base64Decode/Default.aspx" rel="noreferrer">http://www.opinionatedgeek.com/dotnet/tools/Base64Decode/Default.aspx</a> I am getting my Hash Code(opened the .bin file being generated in hex editor).</p> <p>So, is it possible that a single string may have multiple Base64 encoded value?</p> <p>I am using the below code for generating the encoded string:</p> <pre><code> 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; } </code></pre> <p>Kindly, suggest what is going wrong and how to make sure that we use same digest both on client and server side.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload