What's the difference between RSA and Diffie-Hellman? I've been reading on a lot of websites that same thing: RSA is for communication using the public and private key for both the server and client, where Diffie-Hellman is just for exchanging the same secret key that will then be used for both encryption and decryption, but they both depend on the same MATHS, e.g: that question on quoraThen I was confused when I also read that RSA shares a master and pre-master key, as well, like in this question:SO, the question here is, does RSA use the public and private key to encrypt the whole conversation, or is it used just to encrypt a key then the encryption depends on that symmetric key? And if it was used to encrpyt the key and it was the same MATH as Diffie-Hellman, so what is the difference anyways??
Diffie-Hellman Key Exchange

Problem: We have a symmetric encryption scheme and want to communicate. We don't want anybody else to have the key, so we can't say it out loud (or over a wire).

Solution/Mechanics: 


We each pick a number, usually large, and keep it a secret, even from each other. I'll pick $x$, and you'll pick $y$.
We agree on two more numbers, both prime, which anybody can know. We'll call them $g$ and $n$.
I'll calculate $g^x\bmod n$ and tell you my answer. You'll calculate $g^y\bmod n$ and tell me your answer.
Our shared key is $g^{xy}\bmod n = (g^y\bmod n)^x\bmod n = (g^x\bmod n)^y\bmod n$.


RSA Asymmetric Encryption

Problem: I want anybody to be able to encrypt a message, but I'm the only one who can decrypt it. I don't want to share decryption keys with anybody.

Solution/Mechanics: 


I choose two large primes, $p$ and $q$. 
I calculate $n$ such that $pq = n$.
I calculate $t$ such that $(p-1)(q-1) = t$.
I choose an integer $e$ that is both less than $t$ and coprime with $t$.
I find $d$ such that $d$ is the multiplicative inverse of $e$ modulo $t$.
I release $(e, n)$ as my public key, and retain $(d, n)$ as my private key.
When you communicate with me, you treat your message as a large number $m$. The ciphertext $c$ is given by $c = m^e\bmod n$, and decrypted by $m = c^d\bmod n$.