<p>I'm already using <a href="http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/" rel="nofollow noreferrer">salted hashing</a> to store passwords in my database, which means that I should be immune to <a href="https://en.wikipedia.org/wiki/Rainbow_table" rel="nofollow noreferrer">rainbow table</a> attacks.</p>
<p>I had a thought, though: what if someone does get hold of my database? It contains the users' email addresses. I can't really hash these, because I'll be using them to send notification emails, etc..</p>
<p>Should I encrypt them?</p>

[{'answer_id': 70470, 'author': 'Matt Hanson', 'author_id': 5473, 'author_profile': 'https://Stackoverflow.com/users/5473', 'pm_score': 0, 'selected': False, 'text': '<p>You really have to weigh your worst case senario of someone obtaining those email addresses, the likelihood of someone obtaining them, and your extra effort/time needed to impliement the change.</p>\n'}, {'answer_id': 70484, 'author': 'Steve Morgan', 'author_id': 5806, 'author_profile': 'https://Stackoverflow.com/users/5806', 'pm_score': 4, 'selected': False, 'text': "<p>In common with most security requirements, you need to understand the level of threat.</p>\n\n<p>What damage can be done if the email addresses are compromised?</p>\n\n<p>What's the chance of it happening?</p>\n\n<p>The damage done if email addresses are REPLACED could be much greater than if they're EXPOSED. Especially if you're, for example, using the email address to verify password resets to a secure system.</p>\n\n<p>The chance of the passwords being either replaced or exposed is much reduced if you hash them, but it depends what other controls you have in place.</p>\n"}, {'answer_id': 70518, 'author': 'Davy Landman', 'author_id': 11098, 'author_profile': 'https://Stackoverflow.com/users/11098', 'pm_score': 3, 'selected': False, 'text': '<p>I would say it depends on the application of your database.</p>\n\n<p>The biggest problem is, where do you store the encryption key? Because if the hacker has excess to anything more than your DB, all your efforts are probably wasted. (Remember, your application will need that encryption key to decrypt and encrypt so eventually the hacker will find the encryption key and used encryption scheme).</p>\n\n<p>Pro:</p>\n\n<ul>\n<li>A leak of your DB <em>only</em> will not expose the e-mail addresses.</li>\n</ul>\n\n<p>Cons:</p>\n\n<ul>\n<li>Encryption means performance loss.</li>\n<li>Allot of database actions will be harder if not impossible.</li>\n</ul>\n'}, {'answer_id': 70536, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 7, 'selected': True, 'text': '<p>Bruce Schneier has a good response to this kind of problem.</p>\n\n<blockquote>\n  <p>Cryptography is not the solution to your security problems. It might be part of the solution, or it might be part of the problem. In many situations, cryptography starts out by making the problem worse, and it isn\'t at all clear that using cryptography is an improvement.</p>\n</blockquote>\n\n<p>Essentially encrypting your emails in the database \'just in case\' is not really making the database more secure. Where are the keys stored for the database? What file permissions are used for these keys? Is the database accesable publically? Why? What kind of account restrictions are in place for these accounts? Where is the machine stored, who has physical access to this box? What about remote login/ssh access etc. etc. etc.</p>\n\n<p>So I guess you can encrypt the emails if you want, but if that is the extent of the security of the system then it really isn\'t doing much, and would actually make the job of maintaining the database harder.</p>\n\n<p>Of course this could be part of an extensive security policy for your system - if so then great!</p>\n\n<p>I\'m not saying that it is a bad idea - But why have a lock on the door from Deadlocks\'R\'us which cost $5000 when they can cut through the plywood around the door? Or come in through the window which you left open? Or even worse they find the key which was left under the doormat. Security of a system is only as good as the weakest link. If they have root access then they can pretty much do what they want.</p>\n\n<p><a href="https://stackoverflow.com/questions/70450/is-it-worth-encrypting-email-addresses-in-the-database#70484">Steve Morgan</a> makes a good point that even if they cannot understand the email addresses, they can still do a lot of harm (which could be mitigated if they only had SELECT access)</p>\n\n<p>Its also important to know what your reasons are for storing the email address at all. I might have gone a bit overboard with <a href="https://stackoverflow.com/questions/767276/what-is-the-best-and-safest-way-to-store-user-email-addresses-in-the-database">this answer</a>, but my point is do you really need to store an email address for an account? The most secure data is data that doesn\'t exist.</p>\n'}, {'answer_id': 70578, 'author': 'Patrik Svensson', 'author_id': 936, 'author_profile': 'https://Stackoverflow.com/users/936', 'pm_score': 1, 'selected': False, 'text': "<p>@Roo</p>\n\n<p>I somewhat agree to what you are saying but isn't it worth encrypting the data just to make it a little more difficult for someone to get it?</p>\n\n<p>With your reasoning, it would be useless to have locks or alarms in your house, because they can also easily be compromised.</p>\n\n<p><strong>My reply:</strong></p>\n\n<p>I would say that if you have sensitive data that you don't want to fall in the wrong hands, you should probably do it as hard as you can for a hacker to get it, even if it's not 100% fool proof.</p>\n"}, {'answer_id': 70943, 'author': 'massimogentilini', 'author_id': 11673, 'author_profile': 'https://Stackoverflow.com/users/11673', 'pm_score': 2, 'selected': False, 'text': "<p>Both SQL Server and Oracle (and I believe also others DBs) support encryption of data at the database level. If you want to encrypt something why don't simply abstract the access to the data that could be encrypted on the database server side and left the user choose if use the encrypted data (in this case the SQL command will be different) or not. If the user want to user encrypted data then it can configure the database server and all the maintenance work connected with key management is made using standard DBA tool, made from the DB vendor and not from you.</p>\n"}, {'answer_id': 70971, 'author': 'S.Lott', 'author_id': 10661, 'author_profile': 'https://Stackoverflow.com/users/10661', 'pm_score': 2, 'selected': False, 'text': '<p>Don\'t accidentally conflate encryption with obfuscation.  We commonly obfuscate emails to prevent spam.  Lots of web sites will have "webmaster _at_ mysite.com" to slow down crawlers from parsing the email address as a potential spam target.  That should be done in the HTML templates -- there\'s no value to doing this in persistent database storage.</p>\n\n<p>We don\'t encrypt anything unless we need to keep it secret during transmission.  When and where will your data being transmitted?  </p>\n\n<ol>\n<li><p>The SQL statements are transmitted from client to server; is that on the same box or over a secure connection?  </p></li>\n<li><p>If your server is compromised, you have an unintentional transmission.  If you\'re worried about this, then you should perhaps be securing your server.  You have external threats as well as internal threats.  Are ALL users (external and internal) properly authenticated and authorized?</p></li>\n<li><p>During backups you have an intentional transmission to backup media; is this done using a secure backup strategy that encrypts as it goes?</p></li>\n</ol>\n'}, {'answer_id': 769493, 'author': 'Arjan', 'author_id': 84237, 'author_profile': 'https://Stackoverflow.com/users/84237', 'pm_score': 2, 'selected': False, 'text': '<p><em>A copy of my answer at <a href="https://stackoverflow.com/questions/767276/what-is-the-best-and-safest-way-to-store-user-email-addresses-in-the-database/767550#767550">What is the best and safest way to store user email addresses in the database?</a>, just for the sake of the search...</em></p>\n\n<hr>\n\n<p>In general I agree with others saying it\'s not worth the effort. However, I disagree that anyone who can access your database can probably also get your keys. That\'s certainly not true for SQL Injection, and may not be true for backup copies that are somehow lost or forgotten about. And I feel an email address is a personal detail, so I wouldn\'t care about spam but about the personal consequences when the addresses are revealed.</p>\n\n<p>Of course, when you\'re afraid of SQL Injection then you should make sure such injection is prohibited. And backup copies should be encrypted themselves.</p>\n\n<p>Still, for some online communities the members might definitely not want others to know that they are a member (like related to mental healthcare, financial help, medical and sexual advice, adult entertainment, politics, ...). In those cases, storing as few personal details as possible and encrypting those that are required (note that database-level encryption does not prevent the details from showing using SQL Injection), might not be such a bad idea. Again: treat an email address as such personal detail.</p>\n\n<p>For many sites the above is probably not the case, and you should focus on prohibiting <code>SELECT * FROM</code> through SQL Injection, and making sure visitors cannot somehow get to someone else\'s personal profile or order information by changing the URL.</p>\n'}, {'answer_id': 11924021, 'author': 'Nicholas Riley', 'author_id': 1593729, 'author_profile': 'https://Stackoverflow.com/users/1593729', 'pm_score': 4, 'selected': False, 'text': "<p>I realize this is a dead topic, but I agree with Arjan's logic behind this. There are a few things I'd like to point out: \n<br><Br>\n Someone can retrieve data from your database without retrieving your source code (i.e. SQL injection, third-party db's). With this in mind, it's reasonable to consider using an encryption with a key. Albeit, this is only an added measure of security, not the security...this is for someone who wants to keep the email more private than plaintext, \n<b> In the off chance something is overlooked during an update, or an attacker manages to retrieve the emails.</b></p>\n\n<p><b>IMO:</b> If you plan on encrypting an email, store a salted hash of it as well. Then you can use the hash for validation, and spare the overhead of constantly using encryption to find a massive string of data. Then have a separate private function to retrieve and decrypt your emails when you need to use one.</p>\n"}, {'answer_id': 25611683, 'author': 'user3491125', 'author_id': 3491125, 'author_profile': 'https://Stackoverflow.com/users/3491125', 'pm_score': 2, 'selected': False, 'text': "<p>It's worth to encrypt data in Databases, it's not making it a bit more difficult but way more difficult when its encrypted in the right way so stop philosophy and encrypt the sensitive data ;) </p>\n"}, {'answer_id': 66275445, 'author': 'Rutger van Velzen', 'author_id': 7925873, 'author_profile': 'https://Stackoverflow.com/users/7925873', 'pm_score': 1, 'selected': False, 'text': '<p>I miss one important answer here.\nWhen you have European users, you have to comply with the GDPR rules.\nEmail addresses are considered personal data meaning <a href="https://gdpr.eu/article-5-how-to-process-personal-data/" rel="nofollow noreferrer">Art.5</a> does apply on email addresses.</p>\n<blockquote>\n<p>processed in a manner that ensures appropriate security of the\npersonal data, including protection against unauthorised or unlawful\nprocessing and against accidental loss, destruction or damage, using\nappropriate technical or organisational measures (‘integrity and\nconfidentiality’).</p>\n</blockquote>\n<p>Of course this does not say that you must encrypt email addresses. But by encrypting the data you do protect it from snooping employees. And protect yourself as a developer from requests to make a manual change in the database.</p>\n'}]
['https://Stackoverflow.com/questions/70450', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8446/']