Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'str' object has no attribute 'n' with encrypt function implentation #214

Closed
DRISHTANT-DUBEY opened this issue Mar 3, 2023 · 2 comments

Comments

@DRISHTANT-DUBEY
Copy link

DRISHTANT-DUBEY commented Mar 3, 2023

I have been trying to peruse my implentation error im parameters to the encrypt function of your package and seems like the problem wis the way i am passing my public key to the function as params
Error is mentioned in second paragraph

def encrypt(message, key):
    return rsa.encrypt(message.encode('ascii'), key)

publicKey, privateKey = loadKeys()
ciphertext = encrypt(orignal, publicKey)
signature = sign(orignal, privateKey)
text = decrypt(ciphertext, privateKey)

File "C:\Users\dubdri01\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rsa\pkcs1.py", line 194, in encrypt
    keylength = common.byte_size(pub_key.n)
AttributeError: 'str' object has no attribute 'n'

pls help me out to navigate this error

@myheroyuki
Copy link
Collaborator

The error suggests you're passing in the wrong type to rsa.encrypt for the key argument. It should be type rsa.key.PublicKey. It's hard to diagnose anything else since you've omitted the code for loadKeys. Please see the documentation for correct usage. That has everything you need!

@sybrenstuvel
Copy link
Owner

Thanks @myheroyuki for helping out. I'll assume that the issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants