24

I'm going to be storing a few sensitive pieces of information (SSN, Bank Accounts, etc) so they'll obviously need to be encrypted. What strategies do you recommend?

Should I do all the encryption/decryption in the web app itself? Should I use something like pgcrypto and have the conversions done on the DB side? Something else entirely?

Also, if you think I should do encryption on the web app side, what Python libraries would you recommend?

4 Answers 4

5

You can also check django-pgcrypto: https://github.com/dcwatson/django-pgcrypto

Sign up to request clarification or add additional context in comments.

Comments

5

I agree that first you need to consider your overall security model and what threat avenues might be the most risk, a la this article:

https://security.stackexchange.com/questions/16939/is-it-generally-a-bad-idea-to-encrypt-database-fields

but also take a look at these for encrypted fields in Django:

encrypted fields: https://github.com/svetlyak40wt/django-fields

more encrypted fields:

https://github.com/defrex/django-encrypted-fields, https://github.com/django-extensions/django-extensions

1 Comment

django-extensions seems to have removed encrypted fields. github.com/django-extensions/django-extensions/commit/…
2

What are you protecting against? If attacker would get access to your DB/filesystem, he would find how you decrypt data & keys. Hiding your encription key is not an easy task (and rarely implemented in "usual" applications).

I would spend more time on protecting the server and fixing all general security issues.

5 Comments

I agree, and I'm planning to use a fully managed service to run my production setup for precisely that reason -- I know just enough about linux system administration to know how little I know :) That being said, I'd still like to encrypt the fields. I view it as the same type of activity as locking the doors to your house. It's still pretty easy to break in, but it adds a bit of a deterrent.
Then you should stick all your encription & keys on webapp side, so that if DB stolen attacker gets nothing. If files stolen - also nothing. So hardcode key in code, and encrypt/decript all data using AES from standard Python library.
I guess you can also put your key in some wird location, so when blindly copying root of your site, attacker would not get the key.
When you say "AES from standard Python library", what library are you referring to? Does Python ship with a library for AES encryption? Most of the recommendations I've seen are for pycrypto (3rd party).
amk.ca/python/code/crypto.html Ops, actually not in a standard libs, but recommended.
1

If you decide to do the encryption in your web app side and you are using Django for your app, you can take a look django-extensions, especially EncryptedCharField and EncryptedTextField. -> https://github.com/django-extensions/django-extensions/blob/master/docs/field_extensions.rst

1 Comment

django-extensions seems to have removed encrypted fields. github.com/django-extensions/django-extensions/commit/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.