LogCrypt
A command-line tool for prefix-preserving encryption of IP addresses and URIs in logs and data files. Enables privacy-compliant data analysis while maintaining network and URI hierarchies.
Quick Start
# Install
# Generate a secure key
KEY=
# Encrypt an IP address
# Parse and redact a log file
Features
IP Address Encryption with Prefix Preservation
- Prefix-preserving encryption: IPs in the same subnet remain in the same encrypted subnet, enabling network topology analysis without exposing real IPs
- Format-preserving: Encrypted IPs are syntactically valid IP addresses
- Full IPv4 and IPv6 support: Complete protocol coverage
- Deterministic: Same input always produces the same encrypted output, enabling correlation analysis
URI/URL Encryption with Hierarchy Preservation
- Hierarchy-preserving encryption: Maintains URI path structure, preserving the relationship between parent and child paths
- Full URL and path-only support: Handles both complete URLs (https://example.com/api/v1/users) and relative paths (/api/v1/users)
- Component preservation: Encrypts while maintaining query parameters, fragments, ports, and credentials
- Multi-scheme support: Works with http, https, ftp, ssh, and other URI schemes
Log File Processing
- Auto-detection: Automatically identifies Apache, Nginx, JSON, Syslog formats
- Batch processing: Handle entire log files efficiently
- Structure preservation: Maintains original log format
- Multiple operations: Encrypt, decrypt, or redact sensitive data
Additional Features
- Batch processing: Process multiple IPs/URIs from files
- JSON output: Integration-friendly output format
- Environment variables: Store keys securely
- Dry-run mode: Preview changes before applying
Installation
From Source
# Clone the repository
# Build with Cargo
# Binary will be at target/release/logcrypt
Add to PATH (Optional)
# Copy to local bin
# Or system-wide (requires sudo)
Key Management
Generating Keys
LogCrypt requires 256-bit (32-byte) keys with different halves for security:
# Generate a cryptographically secure key (always ensures different halves)
# Save to environment variable
Important: The two 16-byte halves of the key must be different for security reasons. LogCrypt automatically generates keys with this property and validates all keys before use.
Using Environment Variables
Avoid exposing keys in command history by using environment variables:
# Set key once
# Use commands without --key flag
Command Reference
Generate Key
)
Encrypt/Decrypt IP
)
Encrypt/Decrypt URI
)
Parse Logs
)
)
Batch Processing
)
Examples
Basic IP Encryption
# Set your key
# Encrypt an IP
# Output: 45.67.89.123 (example)
# Decrypt it back
# Output: 192.168.1.100
# Notice prefix preservation - IPs in the same subnet
# map to IPs in the same encrypted subnet, preserving network topology
Log File Processing
# Redact all IPs and URLs (no key needed)
# Example output:
# [REDACTED_IP] - - [01/Jan/2024:12:00:00] "GET [REDACTED_URI] HTTP/1.1" 200
# Encrypt sensitive data (reversible with key)
# Decrypt to restore original
# Preview changes without modifying
Batch Processing
# Create input file
# Batch encrypt
# Output (encrypted.json):
{
}
}
}
Working with URIs - Hierarchy Preservation
# URI hierarchy is preserved during encryption
# Parent-child relationships remain intact
# -> https://encrypted.example.com/xyz/abc
# -> https://encrypted.example.com/xyz/abc/def (child of above)
# -> /encrypted/xyz/metrics
# -> /encrypted/xyz/metrics/detailed (child of above)
Security Considerations
Key Security
- Never commit keys to version control
- Use environment variables to avoid command history exposure
- Rotate keys regularly for production systems
- Use different keys for different environments
- Store keys securely using a key management system
Encryption Properties
- Deterministic: Same input → same output (enables correlation and pattern analysis)
- Prefix-preserving: Network topology and URI hierarchies remain analyzable
- Format-preserving: Encrypted data maintains syntactically valid format
- Privacy-preserving: Original values cannot be recovered without the key
- Analysis-friendly: Enables statistical analysis, anomaly detection, and pattern recognition on encrypted data
Best Practices
# Good: Using environment variable
# Bad: Key visible in command history
# Good: Separate keys for different data
Use Cases
Privacy-Compliant Log Analysis
Analyze logs while complying with GDPR, CCPA, and other privacy regulations:
# Encrypt IPs and URIs while preserving their relationships
# Enables network analysis and user behavior analytics without exposing real data
Network Topology Analysis
Share network data with security teams or third parties without exposing infrastructure:
# Preserved subnet relationships enable:
# - Network segmentation analysis
# - Intrusion detection pattern matching
# - Traffic flow analysis
API Usage Analytics
Analyze API usage patterns while protecting endpoint details:
# URI hierarchy preservation allows:
# - API endpoint popularity analysis
# - User flow tracking
# - Performance monitoring by endpoint groups
Security Research and Threat Intelligence
Share anonymized data with security researchers:
# Researchers can analyze:
# - Attack patterns across subnets
# - Lateral movement patterns (preserved IP relationships)
# - Campaign targeting (preserved URI hierarchies)
Multi-Tenant Data Analysis
Enable cross-tenant analytics while maintaining tenant isolation:
# Different encryption keys per tenant preserve:
# - Tenant-specific network patterns
# - API usage patterns per tenant
# - Compliance with data segregation requirements
Troubleshooting
Common Issues
"No key provided" error
# Solution: Set environment variable or use --key flag
"Invalid hex key" error
# Keys must be exactly 64 hex characters (32 bytes)
# Generate a valid key:
"The two halves of the key must be different" error
# Your key has identical 16-byte halves (security issue)
# Solution: Generate a new secure key:
# This automatically ensures the halves are different
Format detection issues
# Force a specific format if auto-detection fails
How Prefix-Preserving Encryption Works
Traditional Encryption vs LogCrypt
Traditional Encryption:
Original: 192.168.1.1 192.168.1.2 192.168.2.1
Encrypted: a7f9c4e3 2b8d1a9f 5e3c7b2a
All relationships lost - useless for analysis
LogCrypt (Prefix-Preserving):
Original: 192.168.1.1 192.168.1.2 192.168.2.1
Encrypted: 45.67.89.1 45.67.89.2 45.67.90.1
Subnet relationships preserved - analysis ready!
Key Benefits
- Maintains Analytical Value: Statistical analysis, pattern recognition, and anomaly detection work on encrypted data
- Preserves Hierarchies: Network topology and API endpoint structures remain intact
- Enables Correlation: Trace requests across systems while protecting sensitive identifiers
- Privacy by Design: Original values cannot be recovered without the encryption key
Architecture
Building Blocks
- IPCrypt-PFX: Advanced format-preserving encryption that maintains IP prefix relationships
- URICrypt: Hierarchy-preserving encryption that maintains URI path relationships
Privacy-Preserving Analysis
Unlike traditional encryption that breaks all relationships, LogCrypt's prefix-preserving approach enables:
- Network Analysis: Identify traffic patterns, bottlenecks, and security issues without seeing real IPs
- User Journey Mapping: Track API usage flows and user behavior patterns while protecting endpoint details
- Anomaly Detection: Detect unusual patterns based on preserved network and URI hierarchies
- Compliance: Meet privacy requirements while maintaining data utility for business operations