PKCS1_PSS sign() method

≯℡__Kan透↙ 提交于 2019-12-11 03:33:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!