Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get back value from Hashed value?

I am trying to get back a string from its hash value?

string str="Hello";
int hashStr=str.GetHashCode(); // hash value of "Hello" is -694847

can I get back my_string (i.e "Hello") form the hashed value....?

UPDATED

actually i am thinking to save password into my database after hashing to make it secure...

So it means a different password even have same value?

like image 242
Javed Akram Avatar asked Nov 28 '22 06:11

Javed Akram


1 Answers

There are exactly 2^32 many hash codes but way, way more strings. Thus, by the pigeonhole principle, there have to be multiple strings mapping to the same hash code. Therefore, an inverse map from hash code to string is impossible

Edit: Response to your update.

actually i am thinking to save password into my database after hashing to make it secure...

So it means a different password even have same value?

Yes, it is possible for two passwords to have the same hash. This is basically a restatement of the above. But you shouldn't use GetHashCode to hash the password. Instead, use something secure like SHA-2.

To go one step further, never try to roll your own your encryption/security etc. Find a library that does it for you.

like image 68
jason Avatar answered Dec 06 '22 17:12

jason