If a web app and a database are on the same server, what is the security benefit of encrypting database data? Obviously passwords should be hashed either way.

I assume that if an attacker can inject some SQL or server code he would be able to view database data. Could somebody more precisely outline the security implications?

Edit: To clarify I was talking about encryption of data. The encryption method is not deterministic so enc(data1) != enc(data1)

1 Answer 1


The pro's:

  • Encrypting the database will ensure that should the database files be leaked they will be inaccessible by the attacker or any other party they are shared with (given the attacker did not also obtain the key/password/user privileges). This means if the server is stolen or old backups are lost or the database files are obtained otherwise the data should remain confidential.

The con's:

  • There is a performance overhead associated with encryption/decryption of the data in the database. This depends greatly on the database system you are using and the type of encryption. It can be ascribed to the fact that every data set that is queried from the database would have to the decrypted to be usable by the web application and similarly all data written to the database would have to be encrypted. These operations can take a long time, especially on large data sets. This performance overhead can be negligible or significant depending on your use and expectations of the database.

The caveat's:

  • Encrypting the database does not protect the data in it if the attack vector is your web app (like the SQLi you mentioned). Your web application accesses the database as a privileged user that can decrypt the data in the database, thus any attack that is executed through your web application will be able to access the encrypted data. This means that a determined attacker would still be able to extract all the data from your database via a SQLi vulnerability.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .