Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using ElGamal ECC to encrypt my plain text data. I want to ensure that my data is safe from a Man-In-The-Middle attack. What methodology I can adopt to achieve this goal?

How can we prevent a Man-In-The-Middle attack while encrypting data by using ElGamal ECC?

share|improve this question
Be sure that you use the correct (authentic) public key of the intended receiver. – DrLecter Sep 1 '14 at 20:40
That rather depends on the goals of the man-in-the-middle. Is it a) to read what you sent (in which case DrLecter's advice is the correct answer), or b) to replace your message with his own (which ElGamal does nothing to prevent; you'll need to sign/MAC your message to prevent that) – poncho Sep 2 '14 at 3:46
Keep in mind that ElGamal is a cryptographic primitive; it is used to build secure cryptographic algorithms that are secure against a multitude of attacks. Just using the primitive alone is not going to cut it. You need padding, authentication, etc. – QuadrExAtt Sep 2 '14 at 6:36

DrLecter is right. It all boils down to making sure to use the right public key. In fact this is the same for any public key cryptosystem be it RSA elGamal or ECC variants thereof.

A MAC or whatever other construction local to your system won't do the job. The MAC e.g. can only make sure the last "editor" of the message knew the symmetric key the message is enciphered with, which a man in the middle obviously always does.

You can only achieve some protection by

  • trusting a CA who signed the key or

  • trusting a PGP style "web of trust" or

  • by meeting your communication partner in person and exchange keys face to face.

A somewhat weaker protection independent of an external organization might be achieved by:

  • Using a second independent and well protected channel to transfer the public key. E.g. use the phone if you trust your mobile...

  • Posting a video where you read your public key aloud. (This helps with people who know you well in person and is hard to fake - I do that with my Academic Signature ECC-key here: . It might be awkward with elGamal or RSA keys which need to be very long nowadays.

  • There are also cryptographic concepts of deterministically deriving a public key from an e-mail address or a name string. This concept is called "Identity Based Encryption" (IBE). You can find it explained in wikipedia. IBE, however, IMHO just transfers the problem and doesn't solve it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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