1

I kind of know the answer to this already but I wanted more of a general opinion of which way to go next.

I want to have users' emails secured by encryption in my application's database, but emails being emails I also want them as an index as well on the user table.

I was doing my seeding of the database and kept getting the error:

[Illuminate\Encryption\DecryptException]  
Invalid data.

I've found that some of the secrets being generated by Crypt::encrypt() seem to exceed the 255 byte limit of MySQL on unique indexes. I guess ultimately I'll have to extend the Encrypter class of the Illuminate package and override the core encryption methods to use something which won't expand the string.

Is there something I'm missing that would do all of this better? it's probably not very query effective to store them as their encrypted format anyways but I couldn't think of anything particularly better?

Peter Fox
  • 1,809
  • 2
  • 20
  • 34
  • Why are you encrypting the e-mails in the first place? – Mike Nov 04 '13 at 17:59
  • Security measure, if the email addresses are encrypted it creates an extra level of difficulty for anyone trying to steal a database as they'll also require the key from the application side. – Peter Fox Nov 04 '13 at 23:32
  • I don't know your specific situation, but I would guess that most databases that store emails don't encrypt the actual stored email. This might be a problem not worth solving. In the big picture of an individual's email address security, encrypting one database entry might not make a difference. http://stackoverflow.com/questions/70450/is-it-worth-encrypting-email-addresses-in-the-database – hayhorse Nov 05 '13 at 02:06
  • This is true, for the moment I've just removed the attribute modifiers so they're not encrypted, it's just a shame as obviously it's an extra bit of security, but in hindsight it's not the end of the world to not have it, it would be nice to know how many extra bytes are added when encrypting though – Peter Fox Nov 05 '13 at 11:34
  • @Sly the extra bytes would depend on the mode of operation you use for the algorithm. Most would default to Cipher-block chaining (CBC), so it would depend on the block and IV size. Also, encrypting email addresses doesn't necessarily make your system more secure - you need to evaluate what your risks are and design your security system with that in mind. – roo Jan 15 '14 at 05:05

1 Answers1

3

Your approach is pointless because Crypt::encrypt() automatically "salts" the values. The same email will generate a different encrypted value each time. Check it by your self:

for($i = 1; $i <= 10; $i++)
{
    echo Crypt::encrypt('secret');
}

Even if you manage to overcome the index column size limit you will still be unable to check for duplicates.

Javi Stolz
  • 4,720
  • 1
  • 30
  • 27