desfire
desfire copied to clipboard
not working in python 2
I found issue in authenticate method.
problem is bytes
which is different in python 2 and python 3
in python 2 it is alias to str:
bytes = str
in python 3 it is: “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256
I think this will explain it better:
In [1]: private_key=[0x00] * 16
In [2]: private_key
Out[2]: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
In [3]: bytes(private_key)
Out[3]: '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]'
In [4]: def bytes(k):
...: return str(bytearray(k))
...:
In [5]: bytes(private_key)
Out[5]: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
problem first appears in line:
k = pyDes.triple_des(bytes(private_key), pyDes.CBC, initial_value, pad=None, padmode=pyDes.PAD_NORMAL)
beacuse pyDes.triple_des
expects sequence of bytes as first parameter it fails
I solved it by hiding original python 2 bytes
with one from my example, but I am not sur wil that work in python 3 and is it right way to solve this issue.
then I found another issue but let solve this first.
Thanks for the info. I will take a look when I get a chance. Was some time ago. I appreciate that! Eoghan
On 9 Jan 2017 08:40, "dejansa" [email protected] wrote:
I found issue in authenticate method.
problem is bytes which is different in python 2 and python 3 in python 2 it is alias to str: bytes = str
in python 3 it is: “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256
I think this will explain it better:
In [1]: private_key=[0x00] * 16
In [2]: private_key Out[2]: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
In [3]: bytes(private_key) Out[3]: '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]'
In [4]: def bytes(k): ...: return str(bytearray(k)) ...:
In [5]: bytes(private_key) Out[5]: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
problem first appears in line: k = pyDes.triple_des(bytes(private_key), pyDes.CBC, initial_value, pad=None, padmode=pyDes.PAD_NORMAL)
beacuse pyDes.triple_des expects sequence of bytes as first parameter it fails
I solved it by hiding original python 2 bytes with one from my example, but I am not sur wil that work in python 3 and is it right way to solve this issue.
then I found another issue but let solve this first.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miohtama/desfire/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AGej7VZy4sSixdFTpbfZ_ehkomrhrz0Jks5rQfKLgaJpZM4LeCIl .
This issue hasn't solved yet? @dejansa how did you solve this issue?