Q
Q
qwertiss2021-06-11 13:08:32
Python
qwertiss, 2021-06-11 13:08:32

Error when converting str to PublicKey to rsa?

I get the keys
(pubkey, privkey) = rsa.newkeys(lenkey)
Then I send the public key via sockets to str
And then I convert it back to PublicKey, but there is a problem

pubkey = rsa.PublicKey.load_pkcs1_openssl_pem(pubkey)

And I get an error
Traceback (most recent call last):
  File "Graphus_server.py", line 30, in <module>
    text = rsaencrypt(msg, encrpubkey)
  File "/root/Graphus/rsad.py", line 9, in rsaencrypt
    pubkey = rsa.PublicKey.load_pkcs1_openssl_pem(pubkey.encode("utf-8"))
  File "/root/.local/lib/python3.6/site-packages/rsa/key.py", line 356, in load_pkcs1_openssl_pem
    der = rsa.pem.load_pem(keyfile, 'PUBLIC KEY')
  File "/root/.local/lib/python3.6/site-packages/rsa/pem.py", line 101, in load_pem
    pem_lines = [line for line in _pem_lines(contents, pem_start, pem_end)]
  File "/root/.local/lib/python3.6/site-packages/rsa/pem.py", line 101, in <listcomp>
    pem_lines = [line for line in _pem_lines(contents, pem_start, pem_end)]
  File "/root/.local/lib/python3.6/site-packages/rsa/pem.py", line 75, in _pem_lines
    raise ValueError('No PEM start marker "%r" found' % pem_start)
ValueError: No PEM start marker "b'-----BEGIN PUBLIC KEY-----'" found

Please tell me why and how to fix it?

Public key output:
PublicKey(8801766261487376824148111200322185322824625344734894881805496796700724762535650830787373742926644434800672995902315661920377179834873774756506576821141149267317394785948848051941558704066215529739504206368806851874791002239054109599899444898780615613914962124598054341920711781832982586441239354111152417672697071612517484189515379114049971039019779478728039397, 65537)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question