# RSA4096 vs AES256 for secure Chat application?

Which of these two methods suits better the implementation of a secure chat application? In this context, chat will be limited up to 150 letters for one message.

I would prefer RSA because what I know RSA is really secure if it is used for small text and also if I will use groups it is easy in RSA because of public key distribution. Specially for chat application where user can write very small letters message I don't know if AES will be good for security. AES is better in performance specially if I will compare 256bit vs 4096bit. RSA will be slower for encrypt and decrypt. But my goal is to have strong secure chat and not super fast chat.

What would be the more apt method?

I will use this chat only for sending message, e.g. no attachments, etc.

• I would advise that you don’t devise your own scheme for a secure chat. Take a look at existing and reviewed crypto protocols and libraries for chat applications. – Jonas Schäfer Jul 1 '17 at 13:42
• Everything depends on your security level. Do you mean neighbourhood level (your next door neighbour who spies you), hacker level (who might listen in for fun) or state level? This decision will govern your choice of key management and distribution. Who do you want to keep out? – Paul Uszak Jul 1 '17 at 13:55
• You may strongly want to consider using the Signal Protocol – SEJPM Jul 1 '17 at 18:25
• It's worth noting that the 4096-bit RSA keyspace is sparse; this is, there aren't $2^{4096}$ valid keys within it. Among other factors, this is one reason you can't directly compare it to AES's 256-bit keyspace. – Nat Jul 2 '17 at 5:17
• If you are making a secure chat application that others will use, i.e. it is not a hobby project for yourself alone, then this is not a question you should be asking. If you ask this for real-world use, use an existing protocol. If you ask this for a non-serious hobby project, then indicate so and use the given answers. – Luc Jul 2 '17 at 11:34

RSA and AES do not oppose, and often are rightly used together in hybrid encryption. RSA can do things that AES can not, like allowing encryption to designated recipients, or allowing anyone to check that a message is not altered or from a different person than is apparent. Using AES or other form of symmetric encryption is a must when encrypting more than few hundred characters.

To choose a cryptosystem, you must first define your goals. Secure chat is not nearly precise enough. Confidentiality? Integrity? Proof of origin? Central registry of participants? How is registration and loss of keys handled?

RSA Pros:

• Public/Private key based, messages can be exchanged without sharing the private key
• Clients only need to send their public key, ensures that the decryption key can't be compromised during exchange.
• Single recipient, a message sent to a specific client can only be read by that client
• Easily revoke client access, to prevent a client from receiving a message all you need to do is not use their public key

RSA Cons:

• Computationally expensive, RSA is very demanding of the cpu
• Battery eater, using RSA frequently will drain the battery of mobile devices

AES Pros:

• Fast/Energy Efficient, most new processors include instruction sets for AES encryption/decryption

AES Cons:

• Key based, requires all clients to know and use the same key
• If the key is leaked, all future communication with that key is compromised
• Anybody with the key can read the message, disallowing for messages to be sent to a specific person within the group
• Unless you have a specific key for each person, no way to remove access for specific people

As fgrieu stated, "hybrid encryption" would be the best choice for your application. Use RSA to exchange an AES key, that way there's no chance for the AES key to be compromised during exchange, and you benefit from both the speed of AES and the security of RSA.

• A few mistakes: clients don't need to just send the public key: they need to make sure that the key is trusted by the senders otherwise an adversary could pose as a receiver. If an RSA private key is leaked then communication to the receiver holding the key just as compromised as the situation for AES. – Maarten - reinstate Monica Jul 1 '17 at 23:58

"But my goal is to have strong secure chat and not super fast chat."

I would advise taking a look at Signal protocol. It is designed exactly for secure messaging and considers a lot of security aspects.

If you ask me the question that way, "RSA or AES"...well...The question should not be asked that way, but here's my answer: I would go for AES128+ and some Diffie-Hellman for key establishing.

Both are quite secure given what we know today and what we think we know about what's coming in the next 20-30 years. Given that I'd chose AES-256.

• You may want to add reasoning to support why you would pick "AES over RSA" to improve your answer. You may also want to adress the concern that two do very different things... – SEJPM Jul 1 '17 at 18:28

Disclaimer: The below answer is to the question-as-asked, rather than seeking to address the use scenario in the question.

### Double crypt

You want to double-crypt; use AES or RSA, then the other. AES is super-fast on modern computers, so using both is basically as fast as RSA alone. So if you're not confident about either one, you may as well use both.

• Encrypt your messages using RSA, then AES.

• Decrypt your mesages using AES, then RSA.

Or, you can flip the order:

• Encrypt your messages using AES, then RSA.

• Decrypt your mesages using RSA, then AES.

RSA's way too slow for most uses, so this isn't a scheme most programmers would consider without a good reason. Plus, there's a lot that you're not doing (e.g. message authentication, protecting against replay attacks, inserting randomness into the messages), so it's probably open to some pretty easy attacks despite both RSA and AES being pretty strong individually, and even moreso together.

But, for the question as you've asked it, it's the way to go.

• Could down-voters explain? – Nat Jul 4 '17 at 7:47
• I did not downvote but: So if you're not confident about either one, you may as well use both. No! just don't use it ! Also recommending a double crypt, is never a good option: e.g. 2xDES allows attack MitM. – Biv Jul 4 '17 at 7:53
• @Biv That logic doesn't follow; if you compare AES+RSA to 2xDES, then either alone is 1xDES, which is vastly weaker. Also, you can't MitM 256-bit AES; the keyspace is too large to fit into our universe according to known physics, much less being feasible on modern hardware. – Nat Jul 4 '17 at 7:59
• I'm not denying that a MitM on 256-bit AES is infeasible. Even attacking a single AES is not in that scale of feasibility. I'm just abstracting the reasoning about double encryption. – Biv Jul 4 '17 at 8:08
• @Biv Yeah, the MitM attack's a popular observation here, though it's so strange. I mean, first, it's completely infeasible - using modern technology, it's better to brute-force than to MitM a large keyspace. Secondly, MitM is just a special case of a space-time tradeoff attack, which is possible against single-cryption schemes, e.g. AES alone; so, stacking cryption schemes doesn't actually introduce any new weakness. I kinda suspect that everyone talks about MitM because it's so easy to understand, but it's also silly. – Nat Jul 4 '17 at 8:10