I am trying to run the pycryptodome
example for DSA. Here is the example code:
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)
But I am facing ImportError
for DSS
. Here is the error output:
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'
My development environment includes:
- Ubuntu 18.04.3 LTS
- Python 3.6.8
- PyCharm IDE 2019.2
- Using
venv
Python virtual environment pip list
command shows:
(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)
Now how do I fix the import error for DSS?