I have a function using the link below to sign or encrypt for me with the RSA algorithm.
[https://stackoverflow.com/questions/75297468/how-to-use-hashalgo-sha256-in-rsa-pkcs1-oaep-encryption-in-pycryptodome]
and use this link: [https://pycryptodome.readthedocs.io/en/latest/src/cipher/oaep.html]
But when I try to use the hashAlgo=SHA256
, it gives me the following error
Expected type 'HashLikeClass | HashLikeModule | None', got 'SHA256.pyi' instead
How can I use hash pattern 256?
from Cryptodome.Cipher import PKCS1_OAEP
from Cryptodome.PublicKey import RSA
import base64
from Cryptodome.Hash import SHA256
def encrypt_1(aes_key_byte):
key = RSA.import_key(open('rsa.public').read())
cipher= PKCS1_OAEP.new(key,hashAlgo=SHA256)
signature =cipher.encrypt(aes_key_byte)
base64_bytes = base64.b64encode(signature)
base64_signature = base64_bytes.decode('ascii')
return base64_signature
Can someone help me?