问题描述
我是使用 Python 进行区块链编程的新手,我正在使用 this 书。
使用以下方法创建私钥和公钥后:
openssl genrsa -out nelsonkey.pem 1024
openssl rsa -in nelsonkey.pem -pubout > nelsonkey.pub
和脚本:
from cryptography.hazmat.primitives import hashes,serialization
from cryptography.hazmat.primitives.asymmetric import padding,rsa
from cryptography.hazmat.backends import default_backend
message = b'Nelson hates cat'
signature = b'Fake signature'
with open('nelsonkey.pub','rb') as key_file:
public_key = serialization.load_pem_public_key(key_file.read(),backend=default_backend())
public_key.verify(signature,message,padding.PSS(mgf=padding.MGF1(hashes.SHA256()),salt_length=padding.PSS.MAX_LENGTH),hashes.SHA256())
print(signature)
我没有看到打印出来的签名,而是得到了不应该得到的异常:
Traceback (most recent call last):
File "verify_message.py",line 11,in <module>
public_key.verify(signature,File "/home/mark/programmingbitcoin/bitcoin/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/rsa.py",line 562,in verify
return _rsa_sig_verify(
File "/home/mark/programmingbitcoin/bitcoin/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/rsa.py",line 283,in _rsa_sig_verify
raise InvalidSignature
cryptography.exceptions.InvalidSignature
对此有什么建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)