I am hashing some sensitive values to support search mechanism as decrypting the values at run-time would be time consuming. I'm using SHA-512 with salt.

For now, things look good. I have the hashes of the original values stored in DB that were hashed with a defined salt. Whenever user tries to search with the search parameter, the input value gets hashed with the same salt and I simply match the two hashed values. That suffices my work.

But now, I want to offer partial search. So, if I have the hash values of "Hello", "Hi", "Howdy" stored and if the users enters "H", all three values should be matched and retrieved.

Is it possible to obtain this functionality?

closed as off-topic by MechMK1, Steffen Ullrich, Xander, Teun Vink, forest Jul 4 at 7:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Information security within the scope defined in the help center." – MechMK1, Steffen Ullrich, Xander, forest
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    This is a programming question, not a security question. – MechMK1 Jul 3 at 11:59
  • 2
    I think it is borderline but it is about using hashes to secure data and search them at the same time without compromising security. I think it is NOT off-toppic because of that. Lets not overmoderate here, if it is not needed. – Peter Harmann Jul 3 at 12:57

No, this is not possible with hashes. Hashes are specifically designed to prevent this, otherwise attacker wanting to obtained the hashed value could start by checking first letter, then the next...

Also, you are likely using salt wrong.


No, you cannot do it.

You want your salts to be long, random or random-like, and unique. Otherwise, an attacker can make a rainbow table for your database based on the salt. Then you will fall victim to targeted precomputation.


Is it possible to obtain this functionality?

No. In fact, having this functionality would make your hash trivially reversible.

Imagine that there is some row that an attacker wants to reverse the hash for. They can:

  • Perform a search for every letter alone (e.g. "A" … "Z"), and check which one of those searches returns the row they are looking for

  • Take that letter, then append every possible second letter (e.g. "HA" … "HZ"), and check which one of those searches returns the row they are looking for

  • etc, continue until the row is found.

Not the answer you're looking for? Browse other questions tagged or ask your own question.