J
J
Just2020-01-02 15:12:06
Python
Just, 2020-01-02 15:12:06

Error while trying to encrypt python/rsa framework data?

5e0dddfbdf335170623275.png
The error itself:

Traceback (most recent call last):
  File "C:\Users\root\Documents\Python Projects\Tests\main.py", line 30, in BtnStartEncrypt
    self.ReturnEncryptData()
  File "C:\Users\root\Documents\Python Projects\Tests\main.py", line 38, in ReturnEncryptData
    encrypt_data = rsa.encrypt(data, public_key)
  File "C:\Users\root\AppData\Local\Programs\Python\Python38\lib\site-packages\rsa\pkcs1.py", line 171, in encrypt
    keylength = common.byte_size(pub_key.n)
AttributeError: 'str' object has no attribute 'n'

Function that doesn't work:
def ReturnEncryptData(self):
    public_key = self.ui.TextPublicKeyEncrypt.text() # QLineText
    data = self.ui.TextEncrypt.toPlainText().encode('utf8') # QEditText
    if data and public_key:
        encrypt_data = rsa.encrypt(data, public_key) # передаем данные которые ввел пользователь в QEditText и QLineEdit
        return self.ui.TextEncrypt.setText(encrypt_data) # возвращаем зашифрованные данные обратно в QEditText

I believe that the error may be that the rsa library does not understand that I gave it the public key, I have been struggling with this problem for the second day, I can’t solve it, I didn’t find an answer on StackOverFlow and Google :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-01-02
@bacon

You don't give it a key, but a string. How to convert a string to a key, read the library docs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question