I am new to cryptography.
In my application we are planning on securing various data using AES GCM to encrypt the data.
Additional to that, let’s say I have a requirement to save some information in a database. This information must not be readable when looked up directly in the database. It’s not critical information like, say, a password.
There is a need that given the same input I should be able to look up the row of the table where this data is stored in the unreadable format in an indexed column. It’s not an issue that anyone can run a query and match this unreadable format with another same value and identify its original input.
If that is not an issue, is it OK to use SHA-256 hashing for this? If not, what's your suggestion for a better alternative?
I have tried searching for this. It appears the trend keeps evolving across the years. To me it looks like it should be OK to do this. But in general I do see many posts discouraging use of SHA. That said, I also saw a post which said even bitcoin uses SHA-256.
I have noted the very helpful inputs. My thanks for the same. As of now, I have understood this much:
- Depending on the sensitivity of the data one can use SHA256 - when not worried about cracking of the data itself too much (but then why even hash it? That said, there may be cases where we can use it)
- Add salt when hashing using SHA-256 if we want to avoid a lookup based on the same password in plain text input. But this can be vulnerable to brute-force attack because of the speed of SHA-256. So don't use this approach also if it’s a password kind of sensitive data
- Use something like Argon2, bcrypt, scrypt which have inbuilt (at least bcrypt has by adding salt into the hash itself) salting. And it can be configured to perform slowly and use more CPU, memory, thereby making it safer.
- Possibly safest which I need to explore further is what was suggested by Topaco—namely a blind index.