Using OpenSSL to build and learn to use RSA key pairs

Source: Internet
Author: User
Tags openssl asymmetric encryption

Asymmetric encryption algorithm is also called < public key algorithm, different from symmetric encryption algorithm, asymmetric encryption algorithm encryption key and decryption key is not a key, asymmetric key pair in the public key can be disclosed.

This algorithm can only be decrypted with the corresponding private key if the public key is used for encryption, or it can only be decrypted with the corresponding public key if encrypted with the private key. It is almost impossible to derive the private key from the public key (such an algorithm can be implemented using some irreversible functions)!

OpenSSL supports RSA, DSA, DH three different asymmetric encryption algorithms. Here we'll explain how to use OpenSSL to build and learn to use RSA key pairs.

RSA Asymmetric Encryption:

First, generate the RSA key pair (OPENSLL Genrsa):

1. Syntax Description:

Usage:genrsa [args] [numbits]

-des encrypt the generated key with DES in CBC mode (encrypted RSA key pair using DES encryption algorithm)

-des3 encrypt the generated key with DES in Ede CBC mode (encrypted RSA key pair using the DES3 encryption algorithm)

-aes128,-aes192,-aes256

Encrypt PEM output with CBC AES (encrypted RSA key pair with AES encryption algorithm)

-out file output the key to '

-passout arg output File pass phrase source (password for output key file)

-f4 use F4 (0x10001) for the E value (using F4 as the e-parameter of the public key, default to this option)

-3 use 3 for the E value (using 3 as the E-parameter of the public key)

-engine e use engine E, possibly a hardware device. (Generating a key pair using a third party device)

-rand file:file: ... (Manually specify random number files)

Load the file (or the "files in" directory) into

The random number generator

2. Case:

(1) OpenSSL genrsa-out Rsakey.pem 2048

Generates a 2048-bit key pair, note: There is no cryptographic operation on the key.

(2) OpenSSL genrsa-aes128-out rsakey.pem-passout pass:111111 2048

Generates a 2048-bit key pair, encrypts the key pair using the AES algorithm, and the key password is 111111

Note: The OpenSSL generated public and private keys are stored in a file by default and can be used to manage key files when a public or private key needs to be extracted using the RSA command.

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.