Secure Peer-to-Peer Chat Application with Advanced Encryption
Features β’ Architecture β’ Installation β’ Usage β’ Security
ChatNet is a modern, cross-platform peer-to-peer chat application built with React Native. It enables secure, real-time communication over local networks (LAN/WiFi) with enterprise-grade encryption and authentication mechanisms.
Unlike traditional chat applications that rely on centralized servers, ChatNet establishes direct TCP connections between devices, ensuring privacy, low latency, and complete control over your data.
- π Privacy-First: No servers, no data collection, no third parties
- π Real-Time: Direct P2P connections with minimal latency
- π‘οΈ Military-Grade Encryption: Multiple encryption algorithms (AES-256, RSA, DES, etc.)
- π Cryptographic Authentication: ECDSA digital signatures prevent message tampering
- π± Cross-Platform: Works on Android and iOS
- π¨ Rich Media: Send text, images, and voice messages
- π Secure Key Exchange: Automated Diffie-Hellman key negotiation
| Algorithm | Type | Key Size | Use Case |
|---|---|---|---|
| AES-256 | Symmetric | 256-bit | Production-ready, high security |
| RSA Hybrid | Asymmetric + Symmetric | 2048-bit RSA + 256-bit AES | Maximum security with perfect forward secrecy |
| Triple DES | Symmetric | 168-bit | Legacy compatibility |
| Playfair | Classical | Variable | Educational purposes |
| Caesar | Classical | 1-25 shift | Educational purposes |
- ECDSA Digital Signatures: Verify message authenticity and integrity
- ECDH Key Exchange: Secure automated key negotiation over insecure channels
- Perfect Forward Secrecy: Each message uses a unique encryption key (RSA mode)
- Anti-Tampering: Automatic detection of modified messages
- π¬ Text Messaging: Encrypted real-time chat
- πΌοΈ Image Sharing: Send photos with automatic compression
- π€ Voice Messages: Record and send audio clips
- β±οΈ Timestamps: Track message history
- π Delivery Status: Real-time connection monitoring
| Requirement | Version | Purpose |
|---|---|---|
| Node.js | β₯ 20.x | JavaScript runtime |
| npm or yarn | Latest | Package manager |
| Git | Latest | Version control |
| Tool | Version | Notes |
|---|---|---|
| Android Studio | Godzilla (2024)+ | IDE |
| JDK | 17 or 21 | Java Development Kit |
| Android SDK | API 35 | Build Tools 35.0.0 |
| Gradle | 8.10.2 | Build system |
| Android Gradle Plugin | 8.7.3 | Build plugin |
Minimum Device Requirements:
- Android 5.0+ (API 21+)
- 100MB free storage
- WiFi or LAN connectivity
| Tool | Version | Notes |
|---|---|---|
| macOS | Ventura (13.0)+ | Operating system |
| Xcode | 14.0+ | IDE |
| CocoaPods | Latest | Dependency manager |
| iOS Deployment Target | 13.4+ | Minimum iOS version |
git clone https://github.com/nnkhanhduy/ChatNet.git
cd ChatNet# Using npm
npm install
# Or using yarn
yarn installcd ios
pod install
cd ..Ensure android/local.properties exists with your SDK path:
sdk.dir=C:\\Users\\YourUsername\\AppData\\Local\\Android\\sdkNote: Replace
YourUsernamewith your actual Windows username.
In your terminal, start the Metro development server:
npm start
# Or with network access for physical devices
npm run start:networkKeep this terminal running throughout development.
Open a new terminal and execute:
# Run on connected device or emulator
npm run android
# Or using React Native CLI
npx react-native run-androidTroubleshooting:
- Enable USB Debugging on your Android device
- Check connected devices:
adb devices - For multiple devices:
adb -s <device_id> install app.apk
# Default simulator
npm run ios
# Specific simulator
npx react-native run-ios --simulator="iPhone 15 Pro"
# Physical device (requires Apple Developer Account)
npx react-native run-ios --device# Using npm script
npm run build:apk
# Or manually
cd android
./gradlew assembleDebug
cd ..
# Output: android/app/build/outputs/apk/debug/app-debug.apknpm run build:release
# Output: android/app/build/outputs/apk/release/app-release.apkConfigure Signing in android/app/build.gradle:
signingConfigs {
release {
storeFile file('my-release-key.keystore')
storePassword 'your-store-password'
keyAlias 'my-key-alias'
keyPassword 'your-key-password'
}
}# Debug APK
npm run install:apk
# Release APK
npm run install:release
# Manual installation
adb install -r path/to/app.apk- Launch the app on both devices
- Ensure both devices are on the same WiFi/LAN network
- Tap the βοΈ Settings icon in the top-right corner
- Note your IP address (e.g.,
192.168.1.100) - Enter Device B's IP in "π Recipient IP"
- Choose encryption mode (recommended: AES or RSA)
- Set encryption key (for AES/DES) or exchange RSA keys
- Note your IP address (e.g.,
192.168.1.101) - Enter Device A's IP in "π Recipient IP"
- Use the same encryption settings as Device A
Device A: Key = "my_secret_key_123"
Device B: Key = "my_secret_key_123" (must match)
Device A:
1. Tap "Generate RSA Keys"
2. Copy your public key
3. Share with Device B (via QR code, text, etc.)
4. Paste Device B's public key in settings
Device B:
1. Tap "Generate RSA Keys"
2. Copy your public key
3. Share with Device A
4. Paste Device A's public key in settings
Device A:
1. Tap "Generate ECDH Keys"
2. Tap "Start Key Exchange"
3. Wait for Device B to respond
Device B:
1. Tap "Generate ECDH Keys"
2. Receive key exchange request
3. Shared key automatically configured β
- Text: Type in the input field and tap send βοΈ
- Images: Tap π· icon and select from gallery
- Voice: Tap and hold π€ to record, release to send
Device A (192.168.1.100):
ββ Recipient IP: 192.168.1.101
ββ Encryption: AES
ββ Key: "secure_key_2024"
ββ Message: "Hello, World!"
ββ Encrypted: "U2FsdGVkX1+..."
ββ Sent via TCP
Device B (192.168.1.101):
ββ Recipient IP: 192.168.1.100
ββ Encryption: AES
ββ Key: "secure_key_2024" (matches Device A)
ββ Received: "U2FsdGVkX1+..."
ββ Decrypted: "Hello, World!" β
ChatNet implements multiple layers of security. For detailed cryptographic specifications, see SECURITY.md.
- Type: Symmetric block cipher
- Key Size: 256 bits
- Mode: CBC with PKCS7 padding
- Use Case: Production environments
- Type: Asymmetric + Symmetric
- RSA Key Size: 2048 bits
- AES Key Size: 256 bits
- Features: Perfect forward secrecy, unlimited message length
- Use Case: Maximum security requirements
- Type: Symmetric block cipher
- Key Size: 168 bits (3 Γ 56-bit keys)
- Mode: CBC
- Use Case: Legacy system compatibility
- Type: Classical digraph substitution
- Use Case: Educational purposes
- Type: Classical substitution
- Shift: 1-25 positions
- Use Case: Educational purposes
- Curve: secp256k1 (Bitcoin curve)
- Hash: SHA-256
- Purpose: Message authentication and integrity verification
- Curve: secp256k1
- Purpose: Secure shared secret generation
- Feature: Automated key negotiation
Important
- Always use AES-256 or RSA Hybrid for production
- Enable Digital Signatures to prevent message tampering
- Use ECDH Key Exchange instead of manual key sharing
- Never share private keys or encryption keys over insecure channels
- Regularly regenerate RSA key pairs
Warning
Caesar and Playfair ciphers are NOT secure for real-world use. They are included for educational purposes only.
ChatNet/
βββ android/ # Android native code
β βββ app/
β β βββ build.gradle # App-level Gradle config
β β βββ src/ # Android source files
β βββ build.gradle # Project-level Gradle config
β
βββ ios/ # iOS native code
β βββ ChatNET/ # iOS app files
β βββ ChatNET.xcodeproj/ # Xcode project
β βββ Podfile # CocoaPods dependencies
β
βββ src/ # Application source code
β βββ components/ # React components
β β βββ ChatInput.tsx # Message input component
β β βββ ChatMessage.tsx # Message display component
β β βββ Header.tsx # App header
β β βββ SettingsModal.tsx # Settings & configuration
β β
β βββ hooks/ # Custom React hooks
β β βββ useTcpSocket.ts # TCP socket management
β β
β βββ utils/ # Utility functions
β β βββ aesCipher.ts # AES-256 encryption
β β βββ caesarCipher.ts # Caesar cipher
β β βββ desCipher.ts # Triple DES encryption
β β βββ playfairCipher.ts # Playfair cipher
β β βββ rsaCipher.ts # RSA hybrid encryption
β β βββ security.ts # ECDSA & ECDH implementation
β β βββ cryptoPolyfill.ts # Crypto polyfills
β β βββ responsive.ts # Responsive scaling utilities
β β
β βββ types.ts # TypeScript type definitions
β βββ constants.ts # App constants
β
βββ assets/ # Static assets
β βββ Logo.jpg # App logo
β
βββ App.tsx # Root component
βββ index.js # App entry point
βββ package.json # Dependencies & scripts
βββ tsconfig.json # TypeScript configuration
βββ babel.config.js # Babel configuration
βββ metro.config.js # Metro bundler config
βββ README.md # This file
βββ SECURITY.md # Security documentation
We welcome contributions from the community! Here's how you can help:
- Check if the issue already exists in Issues
- Create a new issue with:
- Clear title and description
- Steps to reproduce
- Expected vs actual behavior
- Screenshots (if applicable)
- Device info (OS, version, etc.)
- Open an issue with the
enhancementlabel - Describe the feature and its use case
- Explain why it would benefit users
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Test thoroughly on both Android and iOS
- Commit with clear messages:
git commit -m 'Add amazing feature' - Push to your fork:
git push origin feature/amazing-feature - Open a Pull Request
- Follow existing code style (TypeScript, ESLint)
- Add comments for complex logic
- Update documentation for new features
- Ensure backward compatibility
- Test on multiple devices
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 ChatNet Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
ChatNet is built with amazing open-source technologies:
- React Native - Cross-platform mobile framework
- crypto-js - Cryptographic algorithms
- elliptic - Elliptic curve cryptography
- jsrsasign - RSA cryptography
- react-native-tcp-socket - TCP networking
Special thanks to all contributors and the open-source community.
β If you find ChatNet useful, please star this repository! β


