问题
I have been trying to fix an issue but failed countless times. I need to use a method, sign(), and I have the correct library imported, however its still not being recognized.
I'm coding in Python and this is what I have that seems important:
#importing the library
from Crypto.Signature import PKCS1_PSS
[...]
signer = PKCS1_PSS.new(keypair)
sig = PKCS1_PSS.sign(keypair)
But the sign() method is the only thing in the entire code from that library that doesn't get recognized:
"This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items."
Does anyone have any suggestions on how to fix this or know what I'm doing wrong?
回答1:
The documentation of PKCS1_PSS is wrong. It currently says:
from Crypto.Signature import PKCS1_PSS
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto import Random
message = 'To be signed'
key = RSA.importKey(open('privkey.der').read())
h = SHA.new()
h.update(message)
signer = PKCS1_PSS.new(key)
signature = PKCS1_PSS.sign(key)
But it should be the following analogous to the documentation of PKCS1_v1_5
from Crypto.Signature import PKCS1_PSS
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto import Random
message = 'To be signed'
key = RSA.importKey(open('privkey.der').read())
h = SHA.new()
h.update(message)
signer = PKCS1_PSS.new(key)
signature = signer.sign(h)
来源:https://stackoverflow.com/questions/43426748/pkcs1-pss-sign-method