Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrypting fields manually from querying the db? #59

Open
mangoes-git opened this issue Aug 15, 2021 · 1 comment
Open

Decrypting fields manually from querying the db? #59

mangoes-git opened this issue Aug 15, 2021 · 1 comment

Comments

@mangoes-git
Copy link

mangoes-git commented Aug 15, 2021

Hi, I would like to know how to decrypt fields manually from querying the database directly. I am using MySQL and the MySQL CLI.

For example, this is the content of the encrypted field:

� ap�s��vdV8\� �P5�-X�9�m��cB,j�"������> ����j�~0����zah |�_�������H��

I am using https://asecuritysite.com/encryption/ferdecode to decode it (using my secret key) but I get no output.

Thanks

@rahulsa123
Copy link

rahulsa123 commented May 20, 2024

Hi @mangoes-git you can try below steps to get actual value from DB

  • First fetch base64 encoded data from db
    SELECT encode(column_name, 'base64') FROM TABLE_NAME limit 1;
  • Convert base64 encoded string to python object
    `

from django.conf import settings
from django_cryptography.utils.crypto import FernetBytes
import pickle
import base64
fernet = FernetBytes(settings.CRYPTOGRAPHY_KEY)
base64_encoded_data = "...."
pickle.loads(fernet.decrypt(base64.b64decode(base64_encoded_data)))
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants