RSA and diffie hellman is assymetric key algorithmn where there are two kinds of keys i.e public key and private key. If the encryption is done by one users public key then decryption must be done by the private key of same users.
RSA
Key Generation
In this method , first we have to consider two large prime numbers :p,q
After that , calculate n=pq
Then, calculate eulers totient function of n=(p-1)(q-1)
Now, assume e such that , GCD(e, PHI(n))=1 .
Assume d congruent modulo of(e^-1 mod phi(n))
That mean d*e mod phi(n)=1
Public key={e,n}, Private key=={d,n}
Encryption
c=m^e mod n
Decryption
m=c^d mod n
Like this key are generated using RSA . Here initially p, q must be chosen such that they are very large prime numbers so that brute force wont be possible. Like this it would be secure.
Diffie Hellman
This algorithm is used to exchange the the key from sender to receiver securely in asymmetric encryption.
Algorithmn
- Consider the prime number q.
2)Select alpha(a) such that it should be primitive root of q and must be less that q.
3)Assume ,
Xa (private key)<q -User--a
Ya(public key )=Alpha^Xa mod q;
Xb(private key )<q-User --b
Yb(public key)=Alpha^Xb mod q;
Key Generation
At sender
Key=Yb^Xa mod q
At reciever
Key=Ya^Xb mod q