In short: I want to store strings encrypted in the database and decrypt them when i need them. What is the best practice for this?
Context: I am building an application that uses a 3rd party API that requires a login and password. I want to store the credentials that will be used for the 3rd party API in the database as their will be many different credentials. I was looking on the django documentation and on stackoverflow but i only find things that hash passwords.
EDIT: I did some more searching and i realy liked this: https://github.com/georgemarshall/django-cryptography
Anyone some other ideas or opinions on the repository i found?
You should create a custom model field and override the
from_db_value()
andget_prep_value
to encrypted and decrypt the string. You can use many packages to do the encryption algorithm.With cryptography you can do something like:
Note: You should abstract the encryption logic for a more optimal solution.