Transferred from:http://blog.chinaunix.net/uid-7550780-id-2611984.html
two principles of asymmetric algorithms: RSA and DH
Although the symmetric algorithm is efficient, the transmission of the key requires additional channels. The asymmetric algorithm RSA and DH can solve the key transmission problem (of course, they are not limited to the role of this). The names of the two algorithms are derived from the acronym of the algorithm author, hoping that one day it will be possible to have a Chinese-named encryption algorithm. The fundamental principle of asymmetric algorithm is one-way function, f (a) =b, but it is difficult to get a with B.
RSA AlgorithmThe RSA algorithm is based on the principle that large numbers are difficult to decompose. It can be used not only for authentication, but also for key transmission. So how do users A and B use the RSA algorithm to transfer keys? 1: A generates a key K, encrypts k with the public key of B, and sends the resulting ciphertext to B. 2: B decrypts the received key with its own private key, the key can be obtained. (Thanks to the user's reminder, has been modified)
DH AlgorithmThe DH algorithm appears to be used for key transmission. The DH algorithm is implemented based on discrete logarithm. How do users A and B use the RSA algorithm to transfer keys? Before the communication, the user A and B mutually agreed 2 large integers n and g, of which 1, the two integers can be exposed 1) a randomly produces a large integer a, and then calculates KA=GA mod n. (a requires secrecy) 2) b randomly produces a large integer b, then calculates KB=GB mod n. (b need to be confidential) 3) A to send Ka to b,b to send KB to A4) a calculation k=kba mod n5) b calculation k=kab mod n due to Kba mod n= (GB mod n) a mod n= (GA mod n) b mod n, so can be guaranteed The k is the same for both parties, and K is the shared key.
The principle of "turn" two asymmetric algorithms: RSA and DH