A salt isn't necessary here, but..
Rolling your own encryption storage scheme is often the bad practise in something like this, simply because your application will need the key at some point and therefore your application will need to consider key security otherwise it won't actually add anything to your overall security and may make it substantially worse. For example, rather than the email address identifying someone, the hash does instead - a lot of dangerous information can still be derived from "anonymised" data sets if this isn't carefully managed. So, firstly, an important reminder: Use the built in features of your database engine whenever possible.
What's a salt for?
A salt has a primary purpose of ensuring uniqueness of the input to a hash function. This is why it is incredibly important that a salt is generated using high quality random number generators - that'll make sure they're not predictable. Salts are commonly used on password fields because lots of people are going to end up choosing the same low quality passwords - usually the lowest quality one imaginable (literally the word password
) followed by pressing whatever keys satisfy the strength requirements. In other words, multiple people end up with the same password and thus the same hash. If you can crack one, you crack them all, simply because SHA-512("password1!")
is a constant. If you prefix the text with some random value, then every input is unique and thus every hash is too.
Why isn't it needed here?
Email addresses and phone numbers are very likely to be unique for your users already, so the salt isn't strictly necessary for its purpose. Given the intent is to search through the set, you can't compare a salted hash with an unsalted one without needing to generate and compare n hashes for n rows in your dataset, and that would likely be extremely slow. Secondly simply hashing a phone number provides little to no security on its own due to the small search space and relative ease of brute force testing all of them. You could of course attempt to do so anyway, but see paragraph #1 again - it is going to be prone to actually making your dataset less secure.
AES_256 hash value
- AES is not a hash algorithm, it is an encryption algorithm ("Advanced Encryption Standard", AES for short); big difference - one is designed to be reversible, the other is not :)password
) followed by pressing whatever keys satisfy the strength requirements. In other words, multiple people end up with the same password and thus the same hash. If you can crack one, you crack them all, simply becauseSHA-512("password1!")
is a constant - thus the apparent speedup. Adding a per-row value, the "salt", guarantees uniqueness of the input value.