andrewcooke / simple-crypt

Simple, secure encryption and decryption for Python 2.7 and 3
http://pypi.python.org/pypi/simple-crypt
262 stars 76 forks source link

Python3.8 AttributeError: module 'time' has no attribute 'clock' #27

Open tnusraddinov opened 4 years ago

tnusraddinov commented 4 years ago

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/simplecrypt/__init__.py", line 42, in encrypt salt = bytes(_random_bytes(SALT_LEN[LATEST]//8)) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/simplecrypt/__init__.py", line 137, in _random_bytes return _hide(bytearray(getrandbits(8) for _ in range(n))) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/simplecrypt/__init__.py", line 137, in <genexpr> return _hide(bytearray(getrandbits(8) for _ in range(n))) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Crypto/Random/random.py", line 51, in getrandbits return mask & bytes_to_long(self._randfunc(ceil_div(k, 8))) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read return self._singleton.read(bytes) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read return _UserFriendlyRNG.read(self, bytes) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read self._ec.collect() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect t = time.clock() AttributeError: module 'time' has no attribute 'clock'

DykemaBill commented 4 years ago

Looks like this project is maybe dead? I am seeing the same problem.

0xBeacon commented 4 years ago

Same here. Python 3.8.5

DykemaBill commented 4 years ago

I ended-up writing my own using Fernet, you can find it here, works as a library or from command line:

https://github.com/DykemaBill/redirector/blob/master/redirectorencryptpass.py

arunanshub commented 4 years ago

I ended-up writing my own using Fernet, you can find it here, works as a library or from command line:

https://github.com/DykemaBill/redirector/blob/master/redirectorencryptpass.py

Hello @DykemaBill @thatchriseckert, you might consider using pyflocker as it provides better support for ciphers, both symmetric and asymmetric, along with Hashes. It offers a seamless interface to Pycryptodome(x) and pyca/cryptography, by using them as cryptographic backends. It also provides a file encryption tool. Also, the AES modes that do NOT support HMAC can optionally be made to use HMAC internally. Other than that, it also provides Camellia cipher with HMAC support.

All the symmetric ciphers support writing into file and file-like objects, which means, you don't have to write a separate function to perform a file or file-buffer encryption/decryption. Hopefully, this saves a lot of time for the developer.

This module also brings enhancements and additions by improving AES-EAX support for pyca/cryptography, which is NOT present natively. Also, ChaCha20-Poly1305 has been implemented for pyca/cryptography to be compatible with PyCryptodome(x).

ponchety commented 3 years ago

Hi evryone! I have the problem I guess, when I'm trying to .exe the script to encrypt a file in a Lab from GNS3 with an Ubuanto Automated Machine, doesn't work.

root@NetworkAutomation-1:~# python3 encrypt_device_info.py

Input CSV filename (device-creds) : Encryption key (cisco) :

----- device_creds --------------------------------------------------- [['192.168.122.71', 'david', 'cisco'], ['192.168.122.72', 'david', 'cisco'], ['192.168.122.73', 'david', 'cisco'], ['192.168.122.74', 'david', 'cisco'], ['192.168.122.75', 'david', 'cisco']]

Output encrypted filename (encrypted-device-creds): Traceback (most recent call last): File "encrypt_device_info.py", line 24, in dc_out.write( encrypt( key, json.dumps( device_creds_list ) ) ) File "/usr/local/lib/python3.8/dist-packages/simplecrypt/init.py", line 42, in encrypt salt = bytes(_random_bytes(SALT_LEN[LATEST]//8)) File "/usr/local/lib/python3.8/dist-packages/simplecrypt/init.py", line 137, in _random_bytes return hide(bytearray(getrandbits(8) for in range(n))) File "/usr/local/lib/python3.8/dist-packages/simplecrypt/init.py", line 137, in return hide(bytearray(getrandbits(8) for in range(n))) File "/usr/local/lib/python3.8/dist-packages/Crypto/Random/random.py", line 51, in getrandbits return mask & bytes_to_long(self._randfunc(ceil_div(k, 8))) File "/usr/local/lib/python3.8/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read return self._singleton.read(bytes) File "/usr/local/lib/python3.8/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read return _UserFriendlyRNG.read(self, bytes) File "/usr/local/lib/python3.8/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read self._ec.collect() File "/usr/local/lib/python3.8/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect t = time.clock() AttributeError: module 'time' has no attribute 'clock' root@NetworkAutomation-1:~#

The is any advice on how to fix it? I guess there is a library issue, but not sure

ponchety commented 3 years ago

Ok, Already fixed! venv/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py line 77 to t = time.time() and it is now fixed. Have been Googling and seems like t = time.clock() is deprecated