Get a Pentest and security assessment of your IT network.

Cyber Security

Encrypting to Multiple People

TL;DR

You can’t directly encrypt a message for multiple recipients using just one asymmetric key (like RSA or ECC). Each recipient needs their own public key. You either encrypt the same message separately for each person, or use a symmetric key encrypted with each recipient’s public key.

How to Encrypt Messages for Multiple Recipients

  1. Understand Asymmetric Encryption Basics:
    • Asymmetric encryption uses a key pair – a public key and a private key.
    • You encrypt with the recipient’s public key.
    • Only the recipient can decrypt with their corresponding private key.
  2. Option 1: Separate Encryption (Simple, but less efficient)
    • For each recipient, encrypt a copy of the message using their individual public key.
    • This means sending multiple encrypted messages – one for each person.
    • # Example using OpenSSL (replace with your actual keys and file names)
      openssl rsautl -encrypt -pubin -inkey recipient1_public.pem -in message.txt -out encrypted_for_recipient1.enc
      openssl rsautl -encrypt -pubin -inkey recipient2_public.pem -in message.txt -out encrypted_for_recipient2.enc
  3. Option 2: Symmetric Key Encryption (More efficient)
    • Generate a random symmetric key (e.g., using AES). This is your session key.
    • Encrypt the message using this symmetric key.
    • Encrypt the symmetric key separately for each recipient using their public key.
    • Send the encrypted message and all of the individually encrypted symmetric keys to everyone.
    • Each recipient uses their private key to decrypt their copy of the symmetric key, then uses that key to decrypt the message.
  4. Step-by-step Symmetric Key Encryption:
    1. Generate a Symmetric Key:
    2. # Example using OpenSSL (AES-256)
      openssl rand -base64 32 > session_key.txt
    3. Encrypt the Message with the Symmetric Key:
    4. # Example using OpenSSL AES encryption
      openssl enc -aes-256-cbc -salt -in message.txt -out encrypted_message.enc -kfile session_key.txt
    5. Encrypt the Symmetric Key for Each Recipient:
    6. # Example using OpenSSL RSA encryption (replace with actual keys)
      openssl rsautl -encrypt -pubin -inkey recipient1_public.pem -in session_key.txt -out encrypted_session_key_recipient1.enc
      openssl rsautl -encrypt -pubin -inkey recipient2_public.pem -in session_key.txt -out encrypted_session_key_recipient2.enc
    7. Send the Files: Send encrypted_message.enc, encrypted_session_key_recipient1.enc and encrypted_session_key_recipient2.enc to all recipients.
  5. Recipient Decryption Process:
    1. Decrypt their individual symmetric key using their private key.
    2. # Example using OpenSSL RSA decryption (replace with actual keys)
      openssl rsautl -decrypt -privin -inkey recipient1_private.pem -in encrypted_session_key_recipient1.enc -out decrypted_session_key.txt
    3. Decrypt the message using the decrypted symmetric key.
    4. # Example using OpenSSL AES decryption
      openssl enc -aes-256-cbc -d -salt -in encrypted_message.enc -out original_message.txt -kfile decrypted_session_key.txt
  6. Important Considerations:
    • Key Management: Securely distributing public keys is crucial.
    • Padding Schemes: Use appropriate padding schemes (e.g., OAEP for RSA) to prevent attacks.
    • Library Choice: Use well-vetted cryptography libraries (e.g., OpenSSL, Bouncy Castle). Avoid implementing encryption yourself unless you are a security expert.
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