RSA encryption algorithm which based on prime factorizations of large integers is a asymmetric algorithm. An asymmetric algorithm uses a different key for encrypting or decrypting the message; one of the keys must be kept secret which called secret key, and the other key is usually made public which called public key. So RSA encryption also has a secret key and a public key. But how to get secret key and public key? Here is the answer.
1. We have two pairs of keys:
public key = (E, N), sender has this key
secret key = (D, N), receiver has this key
And we have this amazing conclusion:
ciphertext = plaintext^E mod N
plaintext = ciphertext^D mod N
2. Here are steps to get keys:
1) get the two big prime number p and q, and N = p*q ;
2) get the integer L = (p-1)*(q-1);
3) get the integer E, where 1<E<L and GCD(E, L) = 1; (GCD, Greatest Common Divisor)
4) get the integer D, where 1<D<L and E*D mod L = 1;
3. Why?
We know the Euler Theorem:
if GCD(a, b) = 1, a^phi(b) mod b = 1; (the function phi(x) is euler function of x);
So if the receiver want to get the plaintext from ciphertext, he can do this:
plaintext = ciphertext^D mod N
= (plaintext^E mod N)^D mod N
= plaintext^E^D mod N
= plaintext^(E*D) mod N
= plaintext^(E*D mod phi(N)) mod N
= plaintext^(E*D mod (p-1)*(q-1)) mod N
= plaintext^1 mod N
= plaintext
4. The define of the phi(x) is the amount of K:
where 1<=K<=x and GCD(K, x) = 1;
Now, you get the public key (E, N).
How do you get the secret key (D, N)?
So let's brute force RSA!