QCecuring - Enterprise Security Solutions

What Are Public and Private Keys? Asymmetric Cryptography Explained

Cryptography 12 Nov, 2025 · 05 Mins read

Public and private keys are the foundation of modern encryption, digital signatures, and TLS. Here's how key pairs work, where they're used, and what happens when a private key is compromised.


Every TLS certificate, every SSH connection, every Bitcoin transaction, every digitally signed document relies on the same concept: a mathematically linked pair of keys where one is public (shared freely) and one is private (kept secret). Data encrypted with the public key can only be decrypted with the private key. Data signed with the private key can be verified by anyone with the public key.

This is asymmetric cryptography — and it solves the fundamental problem of secure communication: how do two parties establish trust without a pre-existing shared secret?


The Core Concept

A key pair consists of two mathematically related values:

Public key: Shared openly. Anyone can have it. Published in certificates, on key servers, in DNS records. Used to: encrypt data for the key owner, or verify signatures made by the key owner.

Private key: Kept absolutely secret. Only the owner possesses it. Never transmitted, never shared, never exposed. Used to: decrypt data encrypted with the matching public key, or create digital signatures.

The critical property: You cannot derive the private key from the public key. The math is one-way — easy to compute in one direction (private → public), computationally infeasible to reverse (public → private).


How They Work Together

Encryption (Confidentiality)

Alice wants to send a secret message to Bob:

1. Alice obtains Bob's PUBLIC key (from his certificate, key server, etc.)
2. Alice encrypts the message with Bob's public key
3. Alice sends the encrypted message (ciphertext)
4. Bob decrypts with his PRIVATE key (only he has it)
5. Nobody else can decrypt — only Bob's private key works

Eavesdropper sees: ciphertext (useless without Bob's private key)

Digital Signatures (Authenticity + Integrity)

Bob wants to prove he wrote a document:

1. Bob hashes the document: hash = SHA-256(document)
2. Bob signs the hash with his PRIVATE key: signature = Sign(hash, private_key)
3. Bob publishes: document + signature
4. Anyone verifies with Bob's PUBLIC key: Verify(signature, public_key) == hash?
5. If yes: document is authentic (Bob signed it) and unmodified (hash matches)

Forger can't create valid signature without Bob's private key

TLS (Both Combined)

Browser connects to https://bank.com:

1. Server presents certificate (contains server's PUBLIC key)
2. Server signs the handshake with its PRIVATE key (CertificateVerify)
3. Browser verifies signature with server's public key (proves identity)
4. Both perform ECDHE key exchange (using public/private key math)
5. Shared secret derived → symmetric session keys → encrypted communication

Result: browser knows it's talking to the real bank.com (not an impersonator)

Key Pair Algorithms

AlgorithmPublic Key SizePrivate Key SizeSecurity LevelUse Case
RSA-2048256 bytes256 bytes112-bitTLS certs (legacy)
RSA-4096512 bytes512 bytes~140-bitCA signing keys
ECDSA P-25664 bytes32 bytes128-bitTLS certs (modern)
ECDSA P-38496 bytes48 bytes192-bitHigh-security certs
Ed2551932 bytes32 bytes128-bitSSH keys, signatures
X2551932 bytes32 bytes128-bitKey exchange (TLS 1.3)

Where Key Pairs Are Used

TLS/SSL Certificates

Every HTTPS website has a key pair:

  • Private key: On the web server (or in an HSM). Used to prove server identity during TLS handshake.
  • Public key: In the certificate. Sent to every connecting client. Used to verify the server’s identity.
# Generate key pair for TLS
openssl ecparam -genkey -name prime256v1 -out server.key  # Private key
openssl req -new -key server.key -out server.csr          # CSR contains public key
# CA signs the CSR → certificate (public key + identity + CA signature)

SSH Authentication

# Generate SSH key pair
ssh-keygen -t ed25519 -C "user@example.com"
# Creates: ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public)

# Public key → deployed to server (authorized_keys)
# Private key → stays on your machine (never leaves)
# Authentication: server challenges, client signs with private key

Code Signing

  • Private key: In an HSM, used by the build pipeline to sign software
  • Public key: In the code signing certificate, used by end users to verify the signature

Cryptocurrency

  • Private key: Controls your wallet (spend funds)
  • Public key: Derives your wallet address (receive funds)
  • Lose the private key = lose all funds permanently

Email Encryption (S/MIME, PGP)

  • Public key: Published, used by others to encrypt emails TO you
  • Private key: Used to decrypt emails sent to you, and to sign emails FROM you

Protecting the Private Key

The private key is the single most critical secret in any cryptographic system. If it’s compromised:

SystemImpact of Private Key Compromise
TLS certificateAttacker can impersonate your server (MITM)
SSH keyAttacker has access to all servers trusting that key
Code signingAttacker can sign malware as your organization
CA signing keyAttacker can issue certificates for ANY domain
CryptocurrencyAttacker steals all funds

Protection Hierarchy

Best:   HSM (key generated inside, never extractable)
Good:   Cloud KMS (non-exportable, API-only access)
OK:     Encrypted file with passphrase (ssh-keygen -p)
Bad:    Plaintext file with restrictive permissions (chmod 600)
Worst:  Plaintext in source code, config file, or email

What to Do If a Private Key Is Compromised

  1. Revoke immediately — contact your CA to revoke the certificate
  2. Generate new key pair — never reuse a compromised key
  3. Request new certificate — with the new key
  4. Deploy new certificate — to all servers
  5. Investigate — how was the key exposed? Fix the root cause.
  6. Notify — if the compromise affected customers or partners

Common Misconceptions

“The public key encrypts, the private key decrypts” Partially true. For encryption: yes. But for signatures: the private key signs (encrypts the hash), and the public key verifies (decrypts the signature). Both keys can perform cryptographic operations — just different ones.

“Longer keys are always better” Not necessarily. ECC P-256 (32-byte key) provides the same security as RSA-3072 (384-byte key). Key length comparisons only make sense within the same algorithm family.

“If I lose my private key, I can regenerate it from the public key” No. The entire security of asymmetric cryptography depends on this being impossible. If you lose the private key, you must generate a new key pair and get a new certificate.

“My private key is in the certificate” No. The certificate contains only the public key. The private key is a separate file that should never be in the same location as the certificate (except in PKCS#12/PFX bundles which are password-protected).


FAQ

Q: Can someone decrypt my HTTPS traffic if they have my public key? A: No. The public key is… public. Everyone has it (it’s in your certificate). Decryption requires the private key. That’s the entire point of asymmetric cryptography.

Q: What’s the difference between a key pair and a certificate? A: A key pair is the raw cryptographic material (public key + private key). A certificate is a signed document that binds the public key to an identity (domain name, organization). The certificate contains the public key + identity + CA’s signature. The private key is separate.

Q: Should I use RSA or ECC for new key pairs? A: ECC (P-256 or Ed25519) for new deployments. Smaller keys, faster operations, same security. RSA only for legacy compatibility.

Q: How do I check if my private key matches my certificate?

# Compare modulus (RSA) or public key point (ECC)
openssl x509 -noout -modulus -in cert.pem | md5sum
openssl rsa -noout -modulus -in key.pem | md5sum
# If both MD5 hashes match → key and cert are a pair

Q: Can two people have the same key pair? A: Theoretically possible but astronomically unlikely. A 256-bit key has 2²⁵⁶ possible values — more than atoms in the observable universe. Collision is not a practical concern.

Stay Ahead on Crypto & PKI

Monthly insights on certificate management, post-quantum readiness, and enterprise security.

Subscribe Free

Related Insights

SSL/TLS

Fix 'The Certificate Chain Could Not Be Built to a Trusted Root Authority'

Fix the Windows certificate chain trust error. Covers missing root CA, intermediate certificate gaps, AIA/CDP issues, GPO trust distribution, and manual import — with certutil verification commands.

By Shivam sharma

15 May, 2026 · 06 Mins read

SSL/TLSTroubleshootingPKI

PKI

Fix 'The Certificate Template Is Not Available' in AD CS

Fix the AD CS error where certificate templates aren't available for enrollment. Covers template publishing, permissions, version compatibility, and CA type issues with certutil commands.

By Sneha gupta

15 May, 2026 · 06 Mins read

PKITroubleshootingWindows Server

PKI

Fix 'The Revocation Function Was Unable to Check Revocation' Error

Fix the Windows revocation check error that blocks certificate validation, smart card logon, code signing, and HTTPS. Covers CRL distribution point issues, OCSP failures, and certutil diagnostics.

By Shivam sharma

15 May, 2026 · 06 Mins read

PKITroubleshootingWindows Server

Ready to Secure Your Enterprise?

Experience how our cryptographic solutions simplify, centralize, and automate identity management for your entire organization.

Stay ahead on cryptography & PKI

Get monthly insights on certificate management, post-quantum readiness, and enterprise security. No spam.

We respect your privacy. Unsubscribe anytime.