basic concept
RSA is an asymmetric encryption technology, as shown in the figure, that is, assuming that Bob wants to send a document to Alice, Bob encrypts the original document with Alice's public key, and then Alice receives the encrypted document and decrypts it with her private key.
From this example, we can see that encryption and decryption use different keys.
Public key: the key to encrypt the document, both the sender and the receiver have
Private key: the key to decrypt the document, unique to the receiver
For details, please refer to this article: 【Learn Encryption 0】Introduction to Public Key Infrastructure (PKI)
Algorithm principle
RSA is currently the most influential public key encryption algorithm.
The RSA algorithm is based on a very simple number theory fact: it is very easy to multiply two large prime numbers, but it is extremely difficult to factorize the product, so the product can be made public as a public key .
de=1modφ(n) is the encryption algorithm RSA in computer security. In the RSA algorithm, de=1modφ(n) means that de is congruent with 1 on φ(n), that is to say, the remainder of dividing 1 by φ(n) is the same as The remainder of dividing 1 by de is the same.
For example: p=3,q=11,d=7;φ(n)=(p-1)(q-1); n=pq=3×11=33, φ(n)=(p-
1
) (q-1)=2*10=20
from de=1modφ(n),
7e=1mod20
means 7e and 1 are congruent about 20, that is, the remainder is the same, and the remainder of 1 divided by 20 is 1,
then 7e=20k+1 , where k is an integer. For example, if k is 1, then e=3.
Algorithm example
Key calculation:
The plaintext information to be encrypted is m=85, choose: e=7, p=11, q=13
n=p*q=11*13=143
z=(p-1)*(q-1)=10*12=120
e*d=1(mod z)
7 * d( mod 120)=1 -------d=103
encryption operation
公钥:(e,n)=(7,143)
密文c=p^e (mod n)=123
decryption operation
密钥:(d,n)=(103,143)
明文:P=c^d (mod n)=85