It's often said that HTTPS SSL/TLS connections are encrypted and said to be secure because the communication between the server and me is encrypted (also provides server authentication) so if someone sniffs my packets, they will need zillions of years to decrypt if using brute force in theory.

Let's assume I'm on a public wifi and there is a malicious user on the same wifi who sniffs every packet. Now let's assume I'm trying to access my gmail account using this wifi. My browser does a SSL/TLS handshake with the server and gets the keys to use for encryption and decryption.

If that malicious user sniffed all my incoming and outgoing packets. Can he calculate the same keys and read my encrypted traffic too or even send encrypted messages to the server in my name?

HTTPS is secure over public hotspots. Only a public key and encrypted messages are transmitted (and these too are signed by root certificates) during the setup of TLS, the security layer used by HTTPS. The client uses the public key to encrypt a master secret, which the server then decrypts with its private key. All data is encrypted with a function that uses the master secret and pseudo-random numbers generated by each side.

Thus,


the data is secure because it is signed by the master secret and pseudo-random numbers
the master secret and pseudo-random numbers are secure because it uses public-private key encryption when the TLS handshake occurs
the public-private key encryption is secure because:

the private keys are kept secret
public-private key encryption is designed to be useless without the private key
the public keys are known to be legitimate because they are signed by root certificates, which either
came with your computer
or were specifically authorized by you (pay attention to browser warnings!)



Thus, your HTTPS connections and data are safe as long as:  


you trust the certificates that come with your computer,
you take care to only authorize certificates that you trust.

