public key encryption, whats my mistake?
Posted: Thu May 28, 2015 4:30 pm
I started developing a web application.
What gives me the most headaches is security. For example i don't get how public key encryption is secure if communicating data on a public network like the internet.
I think i get the concept:
-I have a private key and a public key.
-It's easy to get the public key from the private key but it's very hard to get the private key from the public key. So it's impractical to break the encryption by calculating the private key from the public key. That's fine, i get this.
-I send the public key to my communication partner. He encrypts a message with it and sends it to me. I decrypt it with my private key.
-He sends me his public key. I can encrypt messages with his public key and he can decrypt them with his private key.
-So no one can listen in on our conversation. Because no one can decrypt the messages send without having the private keys, which are never exposed.
But somewhere there must be a mistake in my thoughts, because a man in the middle attack would be very easy.
I am between partner A and partner B. I intercept the message containing the public key A sends to B and keep it. I send my own public key to B. So if B sends a message to A i get the message encrypted with my public key and can decrypt it with my private key. Then i encrypt it with the public key of A and send it to A.
For example my ISP could to this.
Where is my mistake?
It surely wouldn't be used if it would be so easy.
What gives me the most headaches is security. For example i don't get how public key encryption is secure if communicating data on a public network like the internet.
I think i get the concept:
-I have a private key and a public key.
-It's easy to get the public key from the private key but it's very hard to get the private key from the public key. So it's impractical to break the encryption by calculating the private key from the public key. That's fine, i get this.
-I send the public key to my communication partner. He encrypts a message with it and sends it to me. I decrypt it with my private key.
-He sends me his public key. I can encrypt messages with his public key and he can decrypt them with his private key.
-So no one can listen in on our conversation. Because no one can decrypt the messages send without having the private keys, which are never exposed.
But somewhere there must be a mistake in my thoughts, because a man in the middle attack would be very easy.
I am between partner A and partner B. I intercept the message containing the public key A sends to B and keep it. I send my own public key to B. So if B sends a message to A i get the message encrypted with my public key and can decrypt it with my private key. Then i encrypt it with the public key of A and send it to A.
For example my ISP could to this.
Where is my mistake?
It surely wouldn't be used if it would be so easy.