-1

I am trying to convert a small paragraph into a sequence of numbers (and maybe chars) like the md5 does. I tried md5() in PHP and http://www.myersdaily.org/joseph/javascript/md5.js using JS but I get different result.

I do not know why this is happening, but can you suggest me a way to convert the text to a sequence of chars and numbers (to save them in DB) that will give me the same output? I do not mind if the output is not crypto.

Thank you

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
  • What exact input did you give to your JS MD5 function? I must admit I haven't used hashing and JS, but it might not be the case that you get different output due to a bug. Are you fetching remote data via JS and then hashing it or something similar? It might be that you're really not hashing the same thing to begin with. Anyway, I would also use a hashing library if I were you so I can't suggest an alternative. If your PHP `echo md5('a');` doesn't produce the same thing as JS's `console.log(md5('a'))'; then the js code is definitely buggy. – N.B. Aug 06 '14 at 16:52
  • Binary is a sequence of numbers ;) – pattmorter Aug 06 '14 at 16:57

2 Answers2

0

I would use the base64 encode/decode. Check out the link for the php http://php.net/manual/en/function.base64-encode.php and here is a link with some examples for javascript Base64 encoding and decoding in client-side Javascript

Community
  • 1
  • 1
AJ Allen
  • 61
  • 4
0

If you don't need crypto convert them into Hexadecimal value.

For example "Stack" will be 537461636B. If you want to easily encrypt them, just use xor. This cannot give you different results in any possible language.

in PHP I found this function here PHP convert string to hex and hex to string

in JS I found some code here http://snipplr.com/view/52975/

Community
  • 1
  • 1
Vash
  • 73
  • 8