alvan-lic
A Rust crate for generating and validating time-based license keys with offline validation.
Features
- 🔐 Secure: Uses HMAC-SHA256 for cryptographic signing
- ⏱️ Time-based: Create licenses valid for any duration (hours)
- 🔌 Offline: No internet connection required for validation
- 🚀 Fast: Minimal dependencies and efficient implementation
- 🛡️ Tamper-proof: Any modification to the license key will invalidate it
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or install the CLI tool directly:
Then run the interactive CLI:
Quick Start
use ;
Usage
Generating License Keys
use LicenseGenerator;
let generator = new;
// Generate different duration licenses
let one_hour = generator.generate_key.unwrap;
let one_day = generator.generate_key.unwrap;
let one_month = generator.generate_key.unwrap;
let one_year = generator.generate_key.unwrap;
Validating License Keys
use LicenseValidator;
let validator = new;
match validator.validate_key
Security Considerations
-
Secret Key:
- Use a strong, randomly generated secret key
- Keep your secret key secure and never expose it
- Use different secret keys for different applications
-
Offline Validation:
- The same secret key must be used for generation and validation
- Keys cannot be forged without knowing the secret key
- Validation works completely offline
-
Time Synchronization:
- Ensure system clocks are reasonably synchronized
- Keys are validated against the system's current time
License Format
All license keys start with alvan- followed by a base64-encoded payload and signature.
Example: alvan-MTcwNDQ2NzI4MjoxNzA0NTUzNjgyLkPCt8K3w4Qpw6ZVwq0N...
Error Handling
The crate provides detailed error types:
InvalidFormat: The license key format is incorrectInvalidSignature: The signature doesn't match (wrong secret key)Expired: The license has expiredInvalidData: The license data is corrupted
Examples
See the examples/ directory for more detailed usage examples.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.