For the issue of RSA encryption and decryption, just get it done. First, save the main process for communication or future use.
First, make sure that OpenSSL is installed on your computer. Generally, it is automatically installed on Mac! How to install it ??..... Please Baidu ......
The installation command is as follows:
Sudo apt-Get install OpenSSL
Create a folder anywhere you want to save your public key and key,
Open terminal and run the CD command to enter the folder you created. For example, create a folder named "RSA public key private key" on the desktop and enter the folder. The command
Next we start to generate the public key and key:
1. Generate the RSA private key:
Enter the following command in Terminal (this command will generate a 1024-bit private key ):
OpenSSL genrsa-out rsa_private_key.pem 1024
Press enter, as shown in the following figure:
Now you can see the rsa_private_key.pem file in the RSA public key private key folder.
2. Convert RSA private key to pkcs8 format
OpenSSL pkcs8-topk8-inform PEM-In rsa_private_key.pem-outform PEM-nocrypt
After you press enter, you are required to enter the password and confirm the password. After you press enter, the following content is displayed:
The generated result is the private key in pkcs8 format.
3. Generate a public key:
OpenSSL RSA-In rsa_private_key.pem-out rsa_public_key.pem-pubout
Press ENTER
Now we can see a file named rsa_public_key.pem, which is the public key.
At this point, there will be two files under the folder "RSA public key private key": rsa_private_key.pem and rsa_public_key.pem, which are the public key and private key we need!