What Encryption Should I Use for Database Fields Containing Sensitive Information?

My app has a few fields which will contain sensitive information and I’d like to encrypt them as they are written to the database.

Not being so familiar with encryption methods, I’d be interested in people’s perspectives on which method to use… here are some of the questions and situations in my mind:

  1. Some data will be fixed (ish) length e.g. a key.

  2. Some data will be quite variable length and could be very long, such as a notes field for a client’s personal information.

  3. I’m not very clear about which of the cryptographic functions then perform the appropriate decryption, and whether some of the methods (such as Argon) cannot be decrypted from a database read.

  4. How large a table column to assign for the storage.

Thoughts would be appreciated!

Best wishes,
Antony.

encrypt

1 Like

Hello,
Encrypt with password and decrypt with password are used in cases like this. These options use the AES-256-CBC method.

So on inserting data in your database table you encrypt with password.
When you get the data from your database and want to output it, you use decrypt with password.

Hashed data cannot be “de-hashed”, and that’s its purpose - that’s why it’s used for passwords. On login the generated hash is compared with the one stored in the DB.

1 Like

Great, thanks for the feedback @Teodor!

Should I expect the encrypted data to be a similar length to the original?

Also I remember @JonL mentioned something a few weeks ago about how some DBs, mainly mariaDB and maybe MySQL can encrypt data at the database level.

I remember reading into it a bit then but put it aside till later.

From memory you could still down to choose which columns in which tables were encrypted. I think there was a larger storage/bandwidth cost but it was marginal.

1 Like

Here it is...

2 Likes

Encrypted data is almost the same length, it has some overhead because the salt/iv is also stored with the encrypted data and there can be some padding. Should be no more then 32 bytes overhead.

1 Like

Yes, I can turn on encryption at rest within AWS... Bubble used to use that feature in their AWS storage. So that protects the device being hacked...

... I want to protect backups of the database being hacked which is why I'll use encryption of some individual fields too, probably using the technique Teodor discussed.

I don't quite understand that. Can you elaborate?

Yes.

Encryption at rest protects the data if the device it is stored on is accessed.

But the database will be backed up daily, and (I am assuming that) the backup files will contain un-encrypted data from each field.

So to protect against a hacker accessing a database backup file, I want sensitive information to be stored in the actual database field in an encrypted format, and the de-crypted each time the app accesses it.

Why don't you encrypt the backup on the fly? This is...while it's being generated.

Anyway, you probably need to investigate a bit more as AWS RDS also encrypts automatic backups if you want.

1 Like