django-encrypted-id icon indicating copy to clipboard operation
django-encrypted-id copied to clipboard

ekey includes $ since version 0.3

Open wittfabian opened this issue 6 years ago • 8 comments

Hello, I updated to version 0.3 today. Since then, the ekey has a $ at the beginning.

Example: $C8qooWqMNv8aC2Zrnl7j1A

Python: 2.7 Django: 1.11 django-encrypted-id: 0.3.0

wittfabian avatar Sep 29 '18 14:09 wittfabian

?

wittfabian avatar Oct 28 '18 15:10 wittfabian

The dollar sign has been removed in 0.31. Please update to that.

This will still decrypt older versions, including 0.3 (with dollar sign) and 0.2x (without dollar sign). But the ekey produced will be different.

jatinderjit avatar Oct 29 '18 07:10 jatinderjit

Is there documentation available - general and for regex?

wittfabian avatar Oct 30 '18 09:10 wittfabian

Hi, version 0.3.0 can not decrypt ekeys from version 0.2.0.

In decode(e, sub_key) the variable the_id has the right value, but crc != expected_crc is true.

wittfabian avatar Jul 07 '20 12:07 wittfabian

@jatinderjit, can you look at this please.

amitu avatar Jul 08 '20 15:07 amitu

Without this if, keys from version 0.2.0 are also correctly evaluated in 0.3.X.

            if version == 0:
                expected_crc = binascii.crc32(bytes(the_id)) & 0xffffffff
            else:
                id_str = str(the_id).encode('utf-8')
                expected_crc = binascii.crc32(id_str) & 0xffffffff

Keys from version 0.2.0 return the wrong version in line 84. https://github.com/amitu/django-encrypted-id/blob/master/encrypted_id/init.py#L84

wittfabian avatar Jul 10 '20 07:07 wittfabian

Any updates here?

wittfabian avatar Oct 17 '20 09:10 wittfabian

Hey @wittfabian, sorry for such a late response.

If I understood correctly:

  1. You generated an encrypted id using version 0.2.0
  2. And then tried decrypting that encrypted key using version 0.3.x

If this is what you are trying to do, then I couldn't reproduce it.

SECRET_KEY = "34v*r6xdx^4o0_je66&yp48934&p77d3!dvy-8(s(ear3x1yvr"

encode(123, "abc") == "GOX-Z9nNStjer4tMHaeKZw"  # Version 0.2.0
encode(123, "abc") == "$F7joJ5OUm1IfKyfjBaO2TA"   # Version 0.3.0
encode(123, "abc") == "Rrh_U6BkP01CMZ3r1vYZZQ"  # Version 0.3.1, 0.3.2, 0.3.3

decode("GOX-Z9nNStjer4tMHaeKZw", "abc") == 123  # all versions
decode("$F7joJ5OUm1IfKyfjBaO2TA", "abc") == 123  # Version 0.3.0+
decode("Rrh_U6BkP01CMZ3r1vYZZQ", "abc") == 123  # Version 0.3.1+

Each version should be able to decode the keys generated by the previous versions. If this is not working for you, can you please provide some more details so that I can reproduce this?

jatinderjit avatar Oct 22 '20 08:10 jatinderjit