Blog | G5 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:
  • Option 1: Separate Encryption (Simple, but less efficient)
  • # 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
  • Option 2: Symmetric Key Encryption (More efficient)
  • 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.
  • 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
  • Important Considerations:
  • Exit mobile version