Generate the RSA public key and key on Mac

Source: Internet
Author: User
Tags install openssl openssl rsa

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!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.