Get a Pentest and security assessment of your IT network.

Cyber Security

Online Authentication: Public/Private Key Basics

TL;DR

This guide shows you how to let people securely prove who they are online using a simple public/private key system. It’s more secure than passwords alone, but requires some initial setup.

Setting up the System

  1. Generate Key Pairs: Each user needs two keys – a private key (secret!) and a public key (shared with everyone). You can use tools like OpenSSL for this.
    openssl genrsa -out my_private.pem 2048
    openssl rsa -in my_private.pem -pubout -out my_public.pem
  2. Key Storage: Users must securely store their private key. Losing it means losing access, and if someone else gets it, they can impersonate the user.
    • Consider using password protection for the private key file.
    • Hardware security modules (HSMs) offer the best protection but are more complex.
  3. Public Key Distribution: Users need to share their public keys with those who will verify them.
    • A simple method is a website where users can upload and download public keys.
    • More advanced systems use Public Key Infrastructure (PKI) with Certificate Authorities, but this is beyond the scope of this guide.

Authentication Process

  1. Message Creation: The user creates a message they want to sign (e.g., “I am logging in at 10:00 AM”).
  2. Signing the Message: The user uses their *private* key to create a digital signature of the message.
    openssl dgst -sha256 -sign my_private.pem -out signature.sig message.txt
  3. Sending the Data: The user sends both the original message and the digital signature to the server.
  4. Verification: The server uses the user’s *public* key to verify the signature.
    openssl dgst -sha256 -verify my_public.pem -signature signature.sig message.txt
    • If verification succeeds, it proves that the message was signed by the owner of the private key corresponding to the public key used.
    • If verification fails, the message has been tampered with or wasn’t signed by the correct user.

Important Considerations

  • Hashing: Always hash the message before signing it. This prevents someone from forging a signature on a different message with the same content. The examples above use SHA256, but other secure hashing algorithms are available.
  • Algorithm Choice: RSA is common, but newer algorithms like ECDSA offer better performance and security for similar key lengths.
  • Key Length: Use a sufficiently long key length (e.g., 2048 bits or higher for RSA) to prevent brute-force attacks.
  • Timestamping: Include a timestamp in the message to prevent replay attacks, where an attacker reuses a valid signature from a previous session.
  • cyber security best practices: Regularly audit your key management procedures and ensure private keys are protected.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation