What fieldtype of Django model should I choose to store encrypted data?

I am working on a project the requirement is to store some encrypted data in the database. What is the preferred fieldtype of Django model for storing encrypted data?

I am currently using CharField, however, I am not sure if this is the best approach. Also, should BinaryField be an option?

This depends on ur encryption. if the encription is a password for example django by default uses CharField. but CharField always needs to have a max_length kwarg. so if ur encryption produces a constant length hash use CharField if not u can use TextField.

you can use any field from those, CharField , Textfield bit you need to make sure to store the encrypted string and store it ,so you only store the encrypted desired string, as the Django do in user model app

django-admin

Back to Top