2

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?

Navrang
  • 41
  • 4
  • This seems relevant [**Pycrypto RSA PKCS1 OAEP SHA256 Interoperability with Java**](https://stackoverflow.com/questions/50394730/pycrypto-rsa-pkcs1-oaep-sha256-interoperability-with-java), if not an actual duplicate. – Andrew Henle Feb 25 '23 at 17:12
  • @AndrewHenle I used the link you sent, thank you, but no, my problem was not solved, and also the error `Expected type 'HashLikeClass | HashLikeModule | None', got 'SHA256.pyi' instead` – Navrang Feb 25 '23 at 18:52
  • I have the error in this link and the python code, I don't know about the `hashAlgo=SHA256` maybe I'm using this code wrongly – Navrang Feb 25 '23 at 19:02
  • 1
    The code works for me (see [here](https://replit.com/@3hK8cL8H24hwiS7/MidnightblueAustereCase#main.py)). Possibly an installation issue. – Topaco Feb 25 '23 at 19:56

0 Answers0