<div dir="ltr">Just looking at the code here, are you sure the `key` is a bytes object?<div><br></div><div>Alex</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 14, 2018 at 5:30 PM Fennell, Felix W. <<a href="mailto:felnne@bas.ac.uk">felnne@bas.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm not sure if this the best place to ask for support using Cryptography, apologies if it isn't.<br>
<br>
I am trying to recover and decrypt some data encrypted using Blowfish. I have sample code in PHP which works but I am unable to translate it into Python, which is needed for the end goal of this project.<br>
<br>
My issue seems to stem from the IV value used not being the right type and I seem unable to convert the IV I've been given into the correct type.<br>
<br>
My code so far is here [1]<br>
<br>
The output I get is here [2], the main error being:<br>
<br>
"TypeError: initializer for ctype 'unsigned char *' must be a bytes or list or tuple, not str"<br>
<br>
My debug line [3] says that the IV is 'bytes' and not a 'str' so I'm not sure what is causing this error.<br>
<br>
I briefly experimented with the ctypes library to convert the IV but this got me no further.<br>
<br>
In searching this error I found numerous cases where the cause was passing a string instead of bytes, solved by calling 'encode('utf8') or similar - but I believe I've already accounted for this by using b'value' rather than just 'value'. I did also try using a normal string and calling encode but it made no difference.<br>
<br>
I also experimented using 'os.urandom(32)' to generate a value just to check something would work. It did but I got an error about the wrong length (which makes sense), however the 'type(iv)' debug line said this was 'bytes' as well so I'm not sure how my 'bytes' is different.<br>
<br>
If useful, I am using Python 3.6 (through the official Docker image) and Cryptography 2.2.2.<br>
<br>
Have I missed something completely obvious with this?<br>
<br>
I'm aware the choice of IV is not secure, and that Blowfish is deprecated. Part of this project is to move to a newer encryption method but I need to be able to read the existing data first.<br>
<br>
Any help would be very gratefully received.<br>
<br>
Thanks,<br>
Felix.<br>
<br>
[1] <a href="https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7" rel="noreferrer" target="_blank">https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7</a><br>
<br>
[2] <a href="https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7#gistcomment-2619903" rel="noreferrer" target="_blank">https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7#gistcomment-2619903</a><br>
<br>
[3] <a href="https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7#file-main-py-L8" rel="noreferrer" target="_blank">https://gist.github.com/felnne/b399a0918960696aca5c4324392a72f7#file-main-py-L8</a><br>
<br>
<br>
________________________________<br>
This message (and any attachments) is for the recipient only. NERC is subject to the Freedom of Information Act 2000 and the contents of this email and any reply you make may be disclosed by NERC unless it is exempt from release under the Act. Any material supplied to NERC may be stored in an electronic records management system.<br>
________________________________<br>
_______________________________________________<br>
Cryptography-dev mailing list<br>
<a href="mailto:Cryptography-dev@python.org" target="_blank">Cryptography-dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/cryptography-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/cryptography-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">"I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)<br>"The people's good is the highest law." -- Cicero</div><div dir="ltr">GPG Key fingerprint: D1B3 ADC0 E023 8CA6<br><div><br></div></div></div></div></div>