Public key cryptosystems use different encryption keys and decryption keys. The encryption key is public information, while the decryption key needs to be kept secret.
Public key cryptosystem has many good characteristics, which can be used not only for encryption, but also for authentication and digital signature. However, public key encryption is several orders of magnitude slower than symmetric key encryption.
Symmetric key system has fast encryption and decryption speed and high security strength, but the key is difficult to manage and transmit, so it is not suitable for being used alone in the network.
Key generation
1, choose two big prime numbers, p and q.
2. calculation: n = p * q (p and q are two different big prime numbers and must be kept secret. P and Q are generally required to be safe prime numbers, and the length of N is greater than 5 12bit, mainly because the security of RSA algorithm depends on the factorization of large numbers). There is Euler function (n)=(p- 1)(q- 1).
3. Then the encryption key E is randomly selected, and it is required that E and (p- 1) * (q- 1) are mutually prime.
4. Finally, use Euclid algorithm to calculate the decryption key D, which satisfies de≡ 1(modφ(n)). Where n and d are also coprime. Numbers e and n are public keys and d is private key. Two prime numbers, P and Q, are no longer needed and should be discarded so that no one knows.