Both the parties receive public key of each other.
Now, both the parties calculate the value of secret key.
Why does DH work?
Sender calculates secret key as-
Secret key = (Yr)Xs mod n
Receiver calculates secret key as-
Secret key = (Ys)Xr mod n
Problem-01:
Suppose that two parties A and B wish to set up a common secret key (D-H key) between themselves using the Diffie Hellman key exchange technique. They agree on 7 as the modulus and 3 as the primitive root. Party A chooses 2 and party B chooses 5 as their respective secrets. Their D-H key is-
How does DH work?
Solution-
Given-
n = 7
a = 3
Private key of A = 2
Private key of B = 5
Step-01:
Both the parties calculate the value of their public key and exchange with each other.
Some applications of public key technology include the following.
Encryption
This is the main use of a public key to encrypt messages prior to sending. With asymmetric encryption, both the public and private keys are generated randomly. Anyone can have access to a public key to encrypt data, but only an individual who has the matching private key can decrypt the data.
Since the public and private keys are mathematically connected, they are used together to encrypt and decrypt information. If anyone other than the owner of the private key tries to decrypt the information using the public key, the information will be unreadable.