【发布时间】:2019-09-22 20:52:36
【问题描述】:
我正在尝试为 DSA 运行 pycryptodome example。下面是示例代码:
from Crypto.PublicKey import DSA
from Crypto.Signature import DSS
from Crypto.Hash import SHA256
# Create a new DSA key
key = DSA.generate(2048)
f = open("public_key.pem", "w")
f.write(key.publickey().export_key())
f.close()
# Sign a message
message = b"Hello"
hash_obj = SHA256.new(message)
signer = DSS.new(key, 'fips-186-3')
signature = signer.sign(hash_obj)
但我面对的是ImportError 为DSS。这是错误输出:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/snap/pycharm-professional/154/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/snap/pycharm-professional/154/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/username/Projects/DSA_Example.py", line 2, in <module>
from Crypto.Signature import DSS
ImportError: cannot import name 'DSS'
我的开发环境包括:
- Ubuntu 18.04.3 LTS
- Python 3.6.8
- PyCharm IDE 2019.2
- 使用
venvPython 虚拟环境 -
pip list命令显示:
(venv) username@myubuntu:~/Projects/MyProject/$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
asn1crypto (0.24.0)
cryptography (2.1.4)
decorator (4.1.2)
enum34 (1.1.6)
idna (2.6)
ipaddress (1.0.17)
keyring (10.6.0)
keyrings.alt (3.0)
networkx (1.11)
numpy (1.13.3)
pip (9.0.1)
pycrypto (2.6.1)
pycryptodome (3.9.0)
pygobject (3.26.1)
pyxdg (0.25)
PyYAML (3.12)
rubber (1.4)
SecretStorage (2.3.1)
setuptools (39.0.1)
six (1.11.0)
wheel (0.30.0)
现在如何修复 DSS 的导入错误?
【问题讨论】:
标签: python import pycharm pycrypto pycryptodome