All Products
Search
Document Center

Key generation method

Last Updated: Jan 28, 2021

You can check the key generation methods based on your business requirement. The keys include RSA key, ECC key, and SM2 key.

Prerequisites

You have downloaded and installed OpenSSL tool (V1.1.1 or later version) from OpenSSL official website.

Generate RSA key

  1. Open the OpenSSL tool, and run the following command line to generate a RSA private key. You can select to generate a 1024-bit or 2048-bit private key:
    1. openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
  2. Generate RSA public key based on the RSA private key:
    1. openssl rsa -pubout -in private_key.pem -out public_key.pem

Generate ECC key

  1. Open the OpenSSL tool, and run the following command line to generate an ECC key pair. You must select secp256k1 curve.
    1. openssl ecparam -name secp256k1 -genkey -noout -out secp256k1-key.pem
  2. Generate ECC public key based on secp256k1-key.pem key pair:
    1. openssl ec -in secp256k1-key.pem -pubout -out ecpubkey.pem

Generate SM2 key

  1. Open OpenSSL, and run the following command lin to generate SM2 private key sm2-key.pem.
    1. openssl ecparam -name SM2 -genkey -noout -out sm2-key.pem
  2. Generate the SM2 public key sm2pubkey.pem based on the private key sm2-key.pem.
    1. openssl ec -in sm2-key.pem -pubout -out sm2pubkey.pem