I am new to python and I am trying to create a chat server in python using socket. In my server i want to encrypt and decrypt the message sended from the client to the sever.I am trying to create a key from the server then send it to the client but i got this error: "'function' object is not iterable" . I am following this guide : https://riptutorial.com/python/topic/8710/sockets-and-message-encryption-decryption-between-client-and-server. Here are the code that generate the error:
key_128 = os.urandom(16)
#encrypt CTR MODE session key
en = AES.new(key_128,AES.MODE_CTR,counter = lambda:key_128)
encrypto = en.encrypt(key_128)
and this is the error :
Traceback (most recent call last):
File "test.py", line 4, in <module>
en = AES.new(key_128,AES.MODE_CTR,counter = lambda:key_128)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\AES.py", line 232, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\_mode_ctr.py", line 366, in _create_ctr_cipher
_counter = dict(counter)
TypeError: 'function' object is not iterable
I tried to run this guide on python 2.7 and it run ok. But i run on python 3 it has error. Can some one explain why and help me fix this?
Update :
- I am using
pycryptodome
instead ofPycrypto
because i cant install Pycrypto in my pc. - I did some researches how to fix this. There is the link that said the error is caused by conflict between python-crypto in lib and local/lib ... But i dont think it is. Here is the link https://github.com/nccgroup/Winpayloads/issues/21