The Academy is free // the war room is optional
DAEMONCORE // ACADEMY
← FIELD NOTES

Understanding public keys, private keys, and certificates

2026.09.08//8 MIN READtlsauthenticationsecurity-architecturefundamentals

// The Role of Public and Private Keys

In the realm of secure communications, public and private keys are fundamental. They form the backbone of asymmetric encryption, where one key encrypts data and the other decrypts it. The public key is shared openly while the private key is kept confidential. This separation ensures that only the intended recipient can decrypt the message.

A Concrete Example

Consider a scenario where Alice wants to send a secure message to Bob. Here’s a simplified command sequence using OpenSSL:

# Generate a private key
openssl genpkey -algorithm RSA -out bob_private_key.pem

# Derive the corresponding public key
openssl rsa -pubout -in bob_private_key.pem -out bob_public_key.pem

This generates a private key for Bob, which he keeps secret, and a public key that he can share with anyone. Alice can then encrypt her message using Bob's public key:

# Encrypting the message using Bob's public key
openssl rsautl -encrypt -inkey bob_public_key.pem -pubin -in message.txt -out message.enc

Only Bob can decrypt the message using his private key:

# Decrypting the message using Bob's private key
openssl rsautl -decrypt -inkey bob_private_key.pem -in message.enc -out decrypted_message.txt

What Certificates Assert

Certificates serve as a means of establishing trust by verifying the ownership of a public key. When a user receives a certificate, they can check its validity and confirm that the public key contained within it belongs to the purported owner. Certificates are signed by a trusted Certificate Authority (CA), which attests to their authenticity.

A typical certificate includes:

  • The public key
  • Information about the owner (like a domain name)
  • The issuing CA's information
  • The validity period

Here’s how you might create a self-signed certificate with OpenSSL:

# Generate a self-signed certificate
openssl req -new -x509 -key bob_private_key.pem -out bob_certificate.pem -days 365

Common Mistakes

  • Not securing private keys: The private key should never be shared or exposed. Using file permissions to restrict access is critical. For example:
  chmod 600 bob_private_key.pem
  • Using self-signed certificates in production: For production environments, always rely on certificates signed by a trusted CA to avoid man-in-the-middle attacks.
  • Ignoring certificate expiration: Certificates have a limited validity period. Implement monitoring to alert you before expiration, preventing service interruptions. Check your certificates with:
  openssl x509 -in bob_certificate.pem -noout -dates

Defensive Implications

  • Implement Certificate Pinning: This practice ensures clients only accept a specific certificate or public key, reducing the risk of accepting rogue certificates.
  • Regularly Rotate Keys and Certificates: Periodically replacing keys and certificates can mitigate risks associated with key compromise.

Checklist for Key and Certificate Management

  • [ ] Generate and store private keys securely.
  • [ ] Regularly audit public key usage and permissions.
  • [ ] Use valid certificates from trusted CAs in production.
  • [ ] Monitor certificate expiration dates and renew as necessary.

Conclusion

Understanding public keys, private keys, and certificates is a foundational skill in security architecture. It’s a nuanced area, but once mastered, it empowers you to secure communications effectively. Ensure your learning environment is safe—practice these techniques in a disposable range you control. The DaemonCore Academy curriculum is free, providing a platform to deepen your security skills. Make sure to leverage it as you grow.