1 (edited by jesussotofan 2016-10-25 11:01:23)

Topic: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Hi, I'm using encapsulation wolfcrypt in python in my Raspberry Pi.
I'm trying to encrypt something using aes, but I am getting this error that I can not solve.

My code:

from wolfcrypt import ciphers

vector = "1234567890abcdef";
clave = "1234567890abcdef1234567890abcdef";
texto = "hola mundo";

Aes = ciphers.Aes(clave, ciphers.MODE_CBC, vector);
Aes._set_key(ciphers._ENCRYPTION);

Error:

Traceback (most recent call last):
  File "/home/pi/Desktop/probandoAes.py", line 9, in <module>
    Aes._set_key(ciphers._ENCRYPTION);
  File "/usr/local/lib/python2.7/dist-packages/wolfcrypt/ciphers.py", line 167, in _set_key
    self._enc, self._key, len(self._key), self._IV, _ENCRYPTION)
TypeError: initializer for ctype 'Aes *' must be a cdata pointer, not NoneType
>>> 

Can you offer me some help?

Share

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

UP?

Share

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Hi jesussotofan,

I have asked our python expert to look into this for you. Moises should be in touch soon with a resolution.


Kind Regards,

Kaleb

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Hi Kaleb, do we have some news?

Share

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Hi jesussotofan,

I'm testing it right now on my raspberry pi. I'll let you know the results soon.

[ ]'s

[ ]'s
Moisés

Share

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Hi jesussotofan,

I got the following results:

>>> from wolfcrypt import ciphers
>>> vector = "1234567890abcdef"
>>> clave = "1234567890abcdef1234567890abcdef"
>>> texto = "hola mundo"
>>>
>>> aes = ciphers.Aes(clave, ciphers.MODE_CBC, vector)
>>>
>>> aes.encrypt(texto)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/wolfcrypt/ciphers.py", line 109, in encrypt
    "string must be a multiple of %d in length" % self.block_size)
ValueError: string must be a multiple of 16 in length
>>>
>>> ciphertext = aes.encrypt(texto+"FFFFFF")
>>> ciphertext
"\xd1\x1e\xe16(\x93'\xd9\n\xf4s\x96M\xd6gQ"
>>> aes.decrypt(ciphertext)
'hola mundoFFFFFF'
>>>

The function _set_key(ciphers._ENCRYPTION) should not be called by end users. This is a private function. After creating the Aes object, you should call encrypt() or decrypt() and remember that the param to be encrypted or decrypted must be multiple of 16 in length.

Happy Hacking o/

[ ]'s
Moisés

Share

Re: [SOLVED] TypeError: initializer for ctype 'Aes *' must...

Finally! It works perfectly.
Thanks very much really.

Share