django-cryptography icon indicating copy to clipboard operation
django-cryptography copied to clipboard

BadSignature('Signature is not valid')

Open Romko775 opened this issue 4 years ago • 7 comments

After installation & adding to model

class SomeModel(models.Model):
    email = encrypt(models.EmailField())

raises next error

Traceback (most recent call last):
  File "XXX/env/lib/python3.7/site-packages/django_cryptography/core/signing.py", line 223, in unsign
    version, timestamp, value, sig = struct.unpack(fmt, signed_value)
struct.error: bad char in struct format

During handling of the above exception, another exception occurred:

XXX/env/lib/python3.7/site-packages/django_cryptography/core/signing.py", line 225, in unsign
    raise BadSignature('Signature is not valid')

Romko775 avatar May 23 '20 14:05 Romko775

what version of the library are you using?

thismatters avatar Jul 31 '20 20:07 thismatters

I am getting the same error with:

  • django-cryptography==1.0
  • cryptography==3.0
  • Django==3.0.8
  • djangorestframework==3.11.0
Traceback (most recent call last):
  File ".venv/lib/python3.8/site-packages/django_cryptography/core/signing.py", line 223, in unsign
    version, timestamp, value, sig = struct.unpack(fmt, signed_value)
struct.error: bad char in struct format
  File ".venv/lib/python3.8/site-packages/django_cryptography/core/signing.py", line 225, in unsign
    raise BadSignature('Signature is not valid')
django.core.signing.BadSignature: Signature is not valid

But only because I had legacy, not encrypted data in the database for this field! After I deleted them and created new encrypted values, I no longer get this error! Might be worth adding some helpful hints about this in the error message or documentation.

Gilwyad avatar Aug 06 '20 10:08 Gilwyad

After I deleted them and created new encrypted values, I no longer get this error!

How do I do this please? @Gilwyad @thismatters

This is happening in my production database so I can't just delete all data and start from scratch, but I could delete those specific fields because they are currently blank.

Please help, a significant part of my API is non-responsive because of this error.

I've followed along all the different tutorials and I'm still stuck:

  • https://django-cryptography.readthedocs.io/en/latest/migrating.html

  • https://github.com/georgemarshall/django-cryptography/issues/11#issuecomment-419720581

  • https://github.com/georgemarshall/django-cryptography/issues/45#issuecomment-726843961

  • https://gist.github.com/thismatters/53787f2d021fa5a1df640cd7b98d1185

ademidun avatar Nov 13 '20 16:11 ademidun

When I experienced this I think the root cause was the python container that I was running in changed the way certain dependencies in the cryptography toolchain were presenting. I fixed the issue by upgrading my application to a more recent python release container (3.8).

Best of luck to you in troubleshooting this issue. Be aware that dependency changes up and down your stack can cause this issue. It likely does not mean that your data has been lost, but just that something changed.

thismatters avatar Nov 14 '20 00:11 thismatters

I am getting this error : FieldError at / Unsupported lookup 'exact' for EncryptedCharField or join on the field not permitted, perhaps you meant exact or iexact?

Can someone please help me solve this?

Thank you.

MuhammadShahryiar avatar Apr 20 '21 11:04 MuhammadShahryiar

@MuhammadShahryiar Please see https://github.com/georgemarshall/django-cryptography/issues/10

Given the nature of data encryption, anything other than isnull is not query-able. This is a side affect of encrypting the data in the first place, as the output will change even when the input does not.

thismatters avatar Apr 27 '21 15:04 thismatters

@ademidun any update here on how you solved this issue, please?

aymaneMx avatar Jan 12 '22 15:01 aymaneMx