# RSA: Is it secure to use the private key to encrypt and the public key to decrypt?

This may sound weird: What if I don't let others know my public key, then use my private key to encrypt, and the public key to decrypt? Is this secure? Let me explain a little bit:

Common usuage: use private key to sign and disclose public key, then others can vefriy the data signature use public key

Weird usage: use private key to encrypt and don't disclose public key, in other end use public key to decrypt. notice here I will not disclose private key either so it's not swap In second scenario, if I can keep both keys secure(I mean don't disclose to otheres), does it secure?

• from a mathematical point of view exponent $d$ and $e$ can be swapped, but if you use a common software library to generate your key, public exponent $e$ is usually chosen equal to 65537, so if you swap them you'll put your key under jeopardy. – ddddavidee Sep 8 '15 at 15:06
• It works, but you still have to distribute a public key in order to let know to the others how to encrypt messages in a way that only you can decrypt... however, you should take a look at this question also... it seems to me that your question may be a duplicate – pa5h1nh0 Sep 8 '15 at 16:13
• Hi pa5h1nh0, thanks for your link, that one is not a duplicate , I read that link before I post this one. "but you still have to distribute a public key in order to let know to the others how to encrypt messages in a way that only you can decrypt"---------No, I don't need to if I don't need others send encrypted message to me – Gerry Sep 8 '15 at 22:14

## 2 Answers

No, you generally cannot swap the public and private keys.

Your public key consists of a public exponent and a modulus. The modulus should be known to the person doing the encryption. The public exponent - in general - is a relatively small prime such as 3 or 65537 (Fourth number of Fermat). So given the modulus all an attacker has to do is guess the public key. It's very easy to factor pretty small exponents (I've written software to generate public keys given a private key). The exponent of the private key on the other hand consists of a number that is about as large as the modulus. It cannot be easily factored; the security of RSA relies on this fact.

Currently the majority of software uses RSA with a small public exponent. It is however possible to create an RSA exponent that is the same size as the private exponent. In that case you would have something close to two private keys. Note however that the public key is generally not required to be private. So software may not protect the public key as much as the private key (with regards to e.g. side channel analysis). Sometimes the software may also use padding required for signature generation instead of those for encryption if you present it a public key - mainly due to some weird signature functions required for SSLv3 and TLS 1.0.

So even if your software would accept the public key - RSA is modular exponentiation after all - then by all practical means it not going to be secure.

If you keep both keys secret and use a random public exponent, you can use the private key to encrypt and the "public key" to decrypt. However, that is not necessarily a very good idea.

With both keys secret you would be better off using symmetric encryption, like AES. It is faster, more space efficient and requires only one key. You would probably need to use symmetric encryption anyway, in hybrid encryption with RSA, so you are not losing any security or trusting any additional algorithms.

Alternatively, if you want to use an RSA keypair, just use the public key to encrypt and the private key to decrypt. That lets you use a small public exponent, which normal tools will generate, making encryption faster.