Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to hash and then reform the string later

Tags:

java

hash

I need to hash some strings so I can pass them into some libraries, this is straight forward using the String.hashCode call.

However once everything is processed I'd like to convert the integer generated from the hashCode back into the String value. I could obviously track the string and hashcode values somewhere else and do the conversion there, but I'm wondering is there anything in Java that will do this automatically.

like image 551
Steve Avatar asked Oct 29 '10 09:10

Steve


People also ask

Can you convert hash to string?

A hash is a one way process. Simple answer is you can't.

How do I make a hash string?

In order to create a unique hash from a specific string, it can be implemented using their own string to hash converting function. It will return the hash equivalent of a string. Also, a library named Crypto can be used to generate various types of hashes like SHA1, MD5, SHA256 and many more.

Can the same string have different hashCode?

If two string objects are equal, the GetHashCode method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code.

How do I hash a string in C#?

GetHashCode() method is used to get the hash code of the specified string. When you apply this method to the string this method will return a 32-bit signed integer hash code of the given string.


1 Answers

I think you misunderstand the concept of a hash. A hash is a one way function. Worse, two strings might generate the same hash.

So no, it's not possible.

like image 154
Carra Avatar answered Sep 24 '22 15:09

Carra