Skip to content

How to Generate and Manage RSA/ECDSA Key Pairs with OpenSSL

DodaTech Updated 2026-06-24 2 min read

Key pairs are the foundation of public key cryptography. A key pair consists of a private key (kept secret) and a public key (shared freely). This guide walks through the specific troubleshooting steps to diagnose and resolve key pair generation issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

openssl genrsa 1024

Wrong: Using deprecated genrsa with weak 1024-bit key

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out private.pem

Right: Using genpkey with 2048-bit RSA key

Output

-----BEGIN PRIVATE KEY-----\nKey type: RSA\nKey size: 2048 bits

Prevention

To avoid future issues, follow these best practices:

  • Use at least 2048-bit RSA or 256-bit ECDSA (prime256v1) keys
  • Use genpkey instead of deprecated genrsa/gendsa commands
  • Protect private keys with strong file permissions (chmod 600)
  • Extract public key with openssl pkey -in private.pem -pubout -out public.pem
  • Backup private keys securely -- loss means all certificates become unusable

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with key pair

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world OPENSSL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the difference between RSA and ECDSA keys?|||RSA keys use large prime factorization and range from 2048 to 4096 bits. ECDSA keys use elliptic curve cryptography with smaller key sizes (256 bits) offering equivalent security and better performance.
How do I extract a public key from a private key? Run openssl pkey -in private.pem -pubout -out public.pem. The public key can be shared freely and used to verify signatures or encrypt data.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro