1. What is RSA
RSA is a public-key encryption algorithm that can be used for public key cryptography and digital signatures
2.RSA encryption
The RSA encryption process can be expressed in the following formula
Ciphertext = (plaintext ^e) mod N
The ciphertext of RSA equals the remainder of the e-squared divided by N of the number.
The whole process is very simple, as long as you know e,n can encrypt the plaintext. So the combination of e,n is the public key. Written as "Public key is {e,n}"
3.RSA decryption Process
RSA decryption is also very simple to use the following formula to express:
plaintext = (ciphertext ^d) mod N
So d,n represents the private key (because N is part of the public key, so it can also be said that D is the private key)
Here's how to build E,d,n
4. Key pair Production
Steps for RSA key generation:
(1) Seeking n
(2) L (L is the number used only in the process of generating a key pair),
(3) Ask E
(4) Ask D
1. Ask for n
First find two very large prime p,q
N=p*q (if p,q too small password will become easy to decipher)
2. Ask for L
L is p-1,q-1 least common multiple with LCM (p-1,q-1).
L=LCM (P1, Q1)
3. Ask for E
E is a number larger than 1 and smaller than L. In addition, E and L coprime (greatest common divisor is 1)
1<E<lgcd (e,l)=1
Find out the number of gcd (e,l) =1, and use the pseudo-random number generator to generate E that is greater than 1 and less than L. Then judge whether GCD (e,l) is equal to 1. We can find the greatest common divisor by Euclid's Euclidean method.
Satisfies gcd (e,l) is to ensure that there must be a decryption required D
The public key is generated by finding the E,n
4. Ask for D
The number d is calculated by E. The following relationships must exist between D, E, and L:
1<D<LE*d mod l=1
To find out D is to have the private key
5. Practice
Prepare two prime numbers p=17,q=19
n=17*19=323
L=LCM (17-1,19-1) =LCM (16,18) =144
There are gcd (e,l) =1 available to get e=5,7,11,13,17 ....
There are a lot of options for E, so choose 5 here, so the public key is {e=5,n=323}
D*emod l=1 e=5 can be found d=29
So the private key is {d=29,n=323}
1. Encryption
The plaintext to be encrypted must be less than n
Assuming clear text is 123
Redaction =123^5 MoD 323 =225
2. Decryption
Clear Text =225^29 mod 323=123
RSA encryption algorithm