1

I'm dealing with some small data, which needs padding to help with its security. I need to add random padding to the original string before encrypting it and storing it in a database. Can someone provide a clean/standard way of doing this?

Update

I removed my hackish approach as Zaph recommends AES and a random IV with padding (PKCS#7) as a standard way of doing this. Can anyone provide a clean example, where the original string can be at most 10 characters and the padding is an additional 20?

My attempt at googling failed me. But I'm stilling attempting to solve it. If I get it before someone replies, I'll post an answer.

Artjom B.
  • 58,311
  • 24
  • 111
  • 196
James Oravec
  • 16,761
  • 25
  • 77
  • 145
  • 1
    This does not buy you anything and certainly is non-standard, don't do it if you are looking for security. Instead use CBC mode with a random IV, prepend the IV to the encrypted data. – zaph Mar 15 '16 at 22:37
  • 1
    Using AES and a random IV with padding (PKCS#7) will provide an encrypted output of a minimum if 32-bytes. If you are using the database to do the encryption this may already be an option. – zaph Mar 15 '16 at 22:44
  • @zaph, can you provide a link that demonstrates how to do this? My dbe is mysql. It would also count as a simpler way of doing things, so i'd accept it as an answer – James Oravec Mar 15 '16 at 23:03
  • I have not managed MySQL or any database in 15 years so I can't help you. You really do need to study the MySL documentation. I read somewhere on SO that some DB, possible MySQL, will add an IV and store it in a separate column if the right encrypt call is made or the right configuration is set. – zaph Mar 15 '16 at 23:25

0 Answers0