simple-crypt icon indicating copy to clipboard operation
simple-crypt copied to clipboard

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

Open tnusraddinov opened this issue 4 years ago • 6 comments

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'

tnusraddinov avatar May 17 '20 18:05 tnusraddinov

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

DykemaBill avatar Jul 29 '20 21:07 DykemaBill

Same here. Python 3.8.5

0xBeacon avatar Jul 30 '20 15:07 0xBeacon

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

DykemaBill avatar Jul 30 '20 18:07 DykemaBill

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).

arunanshub avatar Aug 11 '20 19:08 arunanshub

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 avatar Jan 06 '21 18:01 ponchety

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

ponchety avatar Jan 06 '21 19:01 ponchety