Consistency Between Different Cryptographic Hashes (SHA-256) Client-side and Server-side?

Will different Cryptographic Hashes (of same type)  return different values? I need to run a JavaScript version of a SHA-256 hash against some data client side. We will also have a rest api service running that needs to duplicate and produce the same hashes. I've read where certain version of a SHA-256 hash return different values based on who developed it and the platform. So how do we get around this? Also any recommendations for a specific version of SHA-256? The files will be small, 200-400 bytes each.

Thanks!
894359Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Russ SuterCommented:
Ugh, I hate when questions like this come up because it makes me question reality. There SHOULD be only one version of SHA-256 and it should be implemented the same way regardless of platform or language. However, I did find something here (https://www.movable-type.co.uk/scripts/sha256.html) that indicates Javascript implements it differently.

I think my approach would be to write a simple, tiny server-based function that handles the hashing then use some SOAP or JSON to deal with getting Javascript to communicate with that server.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Dave BaldwinFixer of ProblemsCommented:
Yes, there are known differences in hash and encryption implementations.  There are notes about dealing with the differences between PHP and ASP,NET implementations.  You are stuck using the version that is part of your programming language.
0
 
btanExec ConsultantCommented:
SHA 256 regardless of language should always return you that 256 bits length - if it differs it is probably due to encoding binary to Based64, UTF8 (wide char) etc. See these test against various implementation - http://brillout.github.io/test-javascript-hash-implementations/ - eventually the algorithm does not change - here is another test demo http://geraintluff.github.io/sha256/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.