공개 및 개인 키를 생성하는 코드를 작성했습니다. Python 3.7에서는 훌륭하게 작동하지만 Python 3.8에서는 실패합니다. 최신 버전에서 어떻게 실패하는지 모르겠습니다. 몇 가지 해결책을 도와주세요.
코드는 다음과 같습니다.
from Crypto.PublicKey import RSA
def generate_keys():
modulus_length = 1024
key = RSA.generate(modulus_length)
pub_key = key.publickey()
private_key = key.exportKey()
public_key = pub_key.exportKey()
return private_key, public_key
a = generate_keys()
print(a)
Python 3.8 버전의 오류 :
Traceback (most recent call last):
File "temp.py", line 18, in <module>
a = generate_keys()
File "temp.py", line 8, in generate_keys
key = RSA.generate(modulus_length)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py", line 508, in generate
obj = _RSA.generate_py(bits, rf, progress_func, e) # TODO: Don't use legacy _RSA module
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/_RSA.py", line 50, in generate_py
p = pubkey.getStrongPrime(bits>>1, obj.e, 1e-12, randfunc)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 282, in getStrongPrime
X = getRandomRange (lower_bound, upper_bound, randfunc)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 123, in getRandomRange
value = getRandomInteger(bits, randfunc)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 104, in getRandomInteger
S = randfunc(N>>3)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
return self._singleton.read(bytes)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
return _UserFriendlyRNG.read(self, bytes)
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
self._ec.collect()
File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
t = time.clock()
AttributeError: module 'time' has no attribute 'clock'
답변
로부터 파이썬 3.8 문서 :
이 기능은
time.clock()
사용 : 파이썬 3.3부터 사용되지 않습니다 된 후, 제거 된time.perf_counter()
또는time.process_time()
대신에, 당신의 요구 사항에 따라 잘 정의 된 동작을 할 수 있습니다. (bpo -36895 에서 Matthias Bussonnier가 제공 )
답변
키를 생성하는 데 사용하는 모듈은 python 3.3 time.clock () 이후 감가 상각 된 메소드를 호출합니다 .
python 3.7로 다운 그레이드하거나 소스 코드를 변경하여 바꿀 수 있습니다. 그 문제도 열어야합니다.
답변
AttributeError: module 'time' has no attribute 'clock'
해당 모듈이있는 최신 버전의 라이브러리 만 사용한다는 의미로 사용되지 않습니다. 예를 들어, 종속성에 따라 제거 및 설치
Crypto == 1.4.1 또는 Mako == 1.1.2 또는 SQLAlchemy == 1.3.6 // etc
아이디어는 나중에 파이썬 버전을 다운 그레이드 할 필요가 없다는 것입니다. Python 3.8과 호환되는 최신 패키지로 패키지를 업데이트하십시오.