A secure, encrypted messaging application written in C++ with end-to-end encryption capabilities.
- End-to-End Encryption: Messages are encrypted using RSA and AES-like ciphers
- Multi-User Support: Multiple clients can connect simultaneously
- Chat Rooms: Support for multiple chat rooms
- Cross-Platform: Works on Windows, Linux, and macOS
- Console Interface: Simple command-line interface
- Real-Time Messaging: Instant message delivery
- Secure Key Exchange: RSA-based key exchange for secure communication
- Client-Server Model: Centralized server handles message routing
- Multi-Threading: Each client connection handled in separate thread
- Socket Programming: TCP sockets for reliable communication
- Encryption:
- RSA for key exchange and authentication
- Symmetric cipher for message encryption
- Session-based security
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
- Make (optional, for using Makefile)
- Platform-specific network libraries:
- Windows: Winsock2 (included)
- Linux/macOS: POSIX sockets (built-in)
# Build the application
make
# Build debug version
make debug
# Build release version
make release
# Clean build files
make clean
# Install system-wide (Linux/macOS)
sudo make installLinux/macOS:
g++ -std=c++17 -Wall -Wextra -O2 -pthread -o cipherchat main.cppWindows (MinGW):
g++ -std=c++17 -Wall -Wextra -O2 -o cipherchat.exe main.cpp -lws2_32Windows (MSVC):
cl /std:c++17 /O2 main.cpp /Fe:cipherchat.exe ws2_32.lib-
Run the application:
./cipherchat
-
Choose option
1to start server -
Enter the port number (default: 8080)
-
Server will start and listen for connections
-
Run the application:
./cipherchat
-
Choose option
2to connect as client -
Enter server details:
- Server address (default: localhost)
- Port (default: 8080)
- Your username
-
Start chatting!
Once connected as a client, you can use these commands:
- Regular messaging: Just type your message and press Enter
/encrypt <message>- Send an encrypted message/users- List all users in the current room/join <room>- Join a specific chat room/quit- Leave the chat
-
RSA Key Exchange:
- Each client generates RSA key pairs
- Public keys are exchanged for secure communication
- Private keys remain local for decryption
-
Session Encryption:
- Symmetric encryption for message content
- XOR-based cipher with key rotation
- Session-specific encryption keys
-
Message Integrity:
- Timestamp-based message ordering
- Sender verification
- Anti-replay protection
- Using established cryptographic libraries (OpenSSL, libsodium)
- Implementing proper key management
- Adding certificate-based authentication
- Using larger key sizes (2048+ bit RSA)
- Implementing perfect forward secrecy
- Adding secure random number generation
- Input validation and sanitization
CipherChat-CPP/
├── README.md # This file
├── LICENSE # MIT License
├── Makefile # Build configuration
├── main.cpp # Main application source
├── docs/ # Documentation
│ ├── SECURITY.md # Security considerations
│ └── API.md # API documentation
├── examples/ # Usage examples
│ ├── server.sh # Server startup script
│ └── client.sh # Client connection script
└── tests/ # Test files
└── test_crypto.cpp # Cryptographic tests
Default server settings can be modified in the source:
// Default port
int DEFAULT_PORT = 8080;
// Maximum connections
int MAX_CONNECTIONS = 50;
// Chat rooms
std::vector<std::string> DEFAULT_ROOMS = {"General", "Secure", "Tech"};Client behavior can be customized:
// Connection timeout (seconds)
int CONNECTION_TIMEOUT = 30;
// Message buffer size
int BUFFER_SIZE = 1024;
// Auto-reconnect attempts
int MAX_RECONNECT_ATTEMPTS = 3;[TIMESTAMP] USERNAME: MESSAGE_CONTENT
[HH:MM:SS] Alice: Hello, world!
[HH:MM:SS] Bob [ENCRYPTED]: [ENCRYPTED MESSAGE]
/command [parameters]
/encrypt Hello, this is a secret message
/join SecureRoom
/users
/quit
-
Client Connection:
Client -> Server: USERNAME Server -> Client: WELCOME_MESSAGE + AVAILABLE_COMMANDS -
Message Exchange:
Client -> Server: MESSAGE_CONTENT Server -> All Clients: [TIMESTAMP] USERNAME: MESSAGE_CONTENT -
Encrypted Message:
Client -> Server: /encrypt PLAINTEXT_MESSAGE Server -> All Clients: [TIMESTAMP] USERNAME [ENCRYPTED]: [ENCRYPTED MESSAGE]
# Terminal 1 - Start Server
$ ./cipherchat
=== CipherChat-CPP ===
1. Start Server
2. Connect as Client
3. Exit
Choose an option: 1
Enter port (default 8080):
CipherChat Server started on port 8080
Available rooms: General Secure
# Terminal 2 - Client 1
$ ./cipherchat
=== CipherChat-CPP ===
1. Start Server
2. Connect as Client
3. Exit
Choose an option: 2
Enter server address (default localhost):
Enter port (default 8080):
Enter your username: Alice
Connected successfully!
=== CipherChat Client ===
Type your messages (or /quit to exit):
Hello everyone!
[14:30:15] You: Hello everyone!
# Terminal 3 - Client 2
$ ./cipherchat
Choose an option: 2
Enter your username: Bob
Hello Alice!
[14:30:20] Bob: Hello Alice!
[14:30:15] Alice: Hello everyone!# Client sends encrypted message
/encrypt This is a secret message
Encrypted message sent: This is a secret message
# Other clients see:
[14:31:00] Alice [ENCRYPTED]: [ENCRYPTED MESSAGE]-
Port Already in Use:
Error: Failed to bind socket Solution: Use a different port or kill existing process -
Connection Refused:
Error: Failed to connect to server Solution: Ensure server is running and firewall allows connection -
Compilation Errors:
Error: 'thread' is not a member of 'std' Solution: Add -pthread flag and use C++17 standard
Compile with debug information:
make debugEnable verbose output by defining DEBUG:
#define DEBUG 1Firewall Settings:
- Allow incoming connections on chosen port
- Configure NAT/port forwarding if needed
Multiple Network Interfaces:
- Server binds to all interfaces (INADDR_ANY)
- Clients can connect via any valid IP address
- Maximum Concurrent Users: ~100 (limited by system resources)
- Message Throughput: ~1000 messages/second
- Memory Usage: ~2MB base + ~50KB per connected user
- CPU Usage: Low during idle, scales with message frequency
-
Large Deployments:
- Increase socket buffer sizes
- Use connection pooling
- Implement message batching
-
High Security:
- Use hardware random number generators
- Implement secure memory allocation
- Add timing attack protection
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow C++17 standards
- Add unit tests for new features
- Update documentation
- Ensure cross-platform compatibility
- Follow secure coding practices
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by modern encrypted messaging applications
- Built with standard C++ libraries for maximum portability
- Cryptographic concepts based on established security practices
This software is provided for educational and demonstration purposes. While it implements encryption, it should not be considered production-ready without additional security hardening and professional cryptographic review. 3. Enter the port number (default: 8080)
- Server will start and listen for connections
-
Run the application:
./cipherchat
-
Choose option
2to connect as client -
Enter server details:
- Server address (default: localhost)
- Port (default: 8080)
- Your username
-
Start chatting!
Once connected as a client, you can use these commands:
- Regular messaging: Just type your message and press Enter
/encrypt <message>- Send an encrypted message/users- List all users in the current room/join <room>- Join a specific chat room/quit- Leave the chat
-
RSA Key Exchange:
- Each client generates RSA key pairs
- Public keys are exchanged for secure communication
- Private keys remain local for decryption
-
Session Encryption:
- Symmetric encryption for message content
- XOR-based cipher with key rotation
- Session-specific encryption keys
-
Message Integrity:
- Timestamp-based message ordering
- Sender verification
- Anti-replay protection
- Using established cryptographic libraries (OpenSSL, libsodium)
- Implementing proper key management
- Adding certificate-base