-2
$\begingroup$

Is it possible to encrypt with the RSA private key and decrypt with the RSA public key(not for signature) The task is that I have to encrypt the data with a private key. Transfer this data to another person and he decrypted it with a public key, added the data and encrypted it with the same public key and sent it to me. The whole task is written in Python, can there be any libraries for this?

$\endgroup$
4
  • 3
    $\begingroup$ I suggest you ask for a solution to the problem you are trying to solve, including why you want to encrypt with a private key, on security.stackexchange.com People there might be able to help you design a proper solution to your problem. $\endgroup$
    – A. Hersean
    Sep 9 at 8:53
  • $\begingroup$ Thank you very much for your help $\endgroup$
    – albert
    Sep 9 at 8:56
  • 4
    $\begingroup$ It's never sound to decrypt with a public key, because (by definition of public) anyone can decrypt, and that goes against the purpose of encryption. High-level libraries with a well-thought interface therefore won't let you do it. Whatever reason you are trying to do it, it's wrong. Possibly, it's asked to perform signature with the private key, and signature verification using the public key, using a terminology that's vetted wrong by the cryptographic community for the last 30 years (libraries for signature will be happy to do it). Another (unsafe) option is to (mis)use pow directly. $\endgroup$
    – fgrieu
    Sep 9 at 9:42
  • 1
    $\begingroup$ For information: the OP asked the same question on security.stackexchange.com/q/255065/127837 but without describing the underlying issue to solve. So it was closed. $\endgroup$
    – A. Hersean
    Sep 9 at 12:15
3
$\begingroup$

The public key is public. You should consider that anybody can have a copy of it, including an attacker. By encrypting with a private key, anybody could decrypt the data with the public key, defeating the point of encrypting in the first place.

DO NOT DO IT.

$\endgroup$
2
  • $\begingroup$ Thank you for your attention, but in this project, this is exactly how the encryption technique is needed. $\endgroup$
    – albert
    Sep 9 at 9:04
  • $\begingroup$ It's impossible. If anyone can decrypt it, it's not encryption, by definition. You cannot encrypt anything with a private key. It's like asking how you can hide something by putting it in a clear glass box in the middle of Times Square. $\endgroup$ Sep 9 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.