PKCS1_PSS sign() method

2019-07-21 22:25发布

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条回答
Rolldiameter
2楼-- · 2019-07-21 22:48

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)
查看更多
登录 后发表回答