Let's say I have an API call which is supposed to check if email address exists in the DB, without transmitting the actual email address. For that purpose, I've decided to store SHA256 hash of the email address in the DB, and updated client to send SHA256 hash of the email in the API call (instead of plaintext email address).
How can I make this more secure using salt when calculating the hash?
As per my understanding, having a fixed salt is pretty much the same as not having salt at all. Is there any way I can have unique salt per email address, but in such a way that both server and client can calculate them?
Would something like this make sense? If not, can you please explain why?
salt = sha256(email) email_hash = salt + "|" + sha256(email + salt)
Consider the following quote:
The salt value is not secret and may be generated at random and stored with the password hash. A large salt value prevents precomputation attacks, including rainbow tables, by ensuring that each user's password is hashed uniquely. This means that two users with the same password will have different password hashes (assuming different salts are used). In order to succeed, an attacker needs to precompute tables for each possible salt value. The salt must be large enough, otherwise an attacker can make a table for each salt value.
I'm not sure if I'm missing anything or not, but does this mean that even if salt isn't a secret nor random, and everyone knows how to calculate salt for an email address, it would still prevent the attacker from recovering email addresses from hashes using rainbow tables. Because each email would be hashed uniquely. Is that correct?
sha256(email)is not a real salt.