OpenSSL public and private key generation and usage

1. Download OpenSSL and install it

2. Key generation:

Linux users (take Ubuntu as an example)
$ openssl enter the OpenSSL program
OpenSSL >  genrsa -out rsa_private_key.pem 1024  Generate private key
OpenSSL >  pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt  Java developers need to put the private key Convert to PKCS8 format (Note: use the Java development background, and the client iOS should also use this)
OpenSSL>  rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem  to generate the public key
OpenSSL>  exit  ## Exit the OpenSSL program

Windows users in cmd Perform the following operations in the window:
C:\OpenSSL-Win32\bin Enter the OpenSSL installation directory
C:\OpenSSL-Win32\bin> openssl.exe  Enter the OpenSSL program
OpenSSL>  genrsa -out rsa_private_key.pem 1024  Generate the private key
OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt  Java developers need to convert the private key to PKCS8 format
OpenSSL>  rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem  generate public key
OpenSSL>  exit  ## Exit the OpenSSL program

Attention Attention Attention:

genrsa -out rsa_private_key.pem 1024   

rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem

These two sentences will generate the rsa_private_key.pem file and the rsa_public_key.pem file in the bin directory of the OpenSSL installation directory, storing the private key and public key respectively.

 pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

This sentence will print the value of a private key in the cmd window. Note that this value is different from the value in the rsa_private_key.pem file above.

If you are developing in Java, use the value printed in the cmd window

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324456361&siteId=291194637