A secure, Native AOT-compiled licensing framework for .NET 8.0 applications with hardware binding, JWT-based authentication, and anti-tampering mechanisms.
- π Hardware Binding (HWID): Unique machine fingerprinting using system UUID, motherboard serial, and CPU ID
- π« JWT-Based Licensing: Secure token generation with configurable expiration (5 minutes to 1 year)
- β‘ Native AOT Compilation: Protection against decompilation and reverse engineering
- π P/Invoke Interoperability: Enables integration with native code and cross-language applications
- π‘ Background License Monitoring: Real-time validation via license shadow checking and timer display
- π Free Trial Management: Time-limited trials with daily usage restrictions
- π‘οΈ Anti-Tampering: File integrity checks and automatic shutdown on license violation
- π AES Encryption: Secure license storage with hardware-derived keys
- Requirements
- Installation
- Quick Start
- Building the DLL
- Usage Examples
- Detailed Usage Guide
- API Reference
- Configuration
- Security Features
- Trial System
- Architecture
- Contributing
- License
- .NET 8.0 SDK or later
- Windows x64 operating system
- Visual Studio 2022 or compatible IDE (optional)
Microsoft.IdentityModel.JsonWebTokens(v8.12.1)System.IdentityModel.Tokens.Jwt(v8.12.1)System.Management(v9.0.7)
- Clone the repository:
git clone https://github.com/yourusername/ButterAuth-Native-1.git
cd ButterAuth-Native-1- Restore dependencies:
dotnet restore- Build the project:
dotnet buildTo compile the project as a Native AOT DLL:
dotnet publish -c Release -r win-x64 --self-contained /p:NativeLib=Sharedusing System.Runtime.InteropServices;
class Program
{
const string DllName = "ButterAuth-Native-1.dll";
[DllImport(DllName, EntryPoint = "Initialize", CallingConvention = CallingConvention.Cdecl)]
public static extern void Initialize();
[DllImport(DllName, EntryPoint = "StartLicenseShadow", CallingConvention = CallingConvention.Cdecl)]
public static extern int StartLicenseChecker(int checkIntervalSeconds);
[DllImport(DllName, EntryPoint = "StopLicenseChecker", CallingConvention = CallingConvention.Cdecl)]
public static extern byte StopLicenseChecker(int instanceId);
static void Main(string[] args)
{
try
{
// Initialize the license system
Initialize();
// Start the license checker with 30 second intervals
int licenseCheckerId = StartLicenseChecker(30);
// Your application logic here
Console.WriteLine("Application running with license protection...");
// Application loop
while (true)
{
Thread.Sleep(1000);
// Your main application code
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}# Standard Native AOT DLL build
dotnet publish -c Release -r win-x64 --self-contained /p:NativeLib=Shared
# Alternative build command
dotnet publish --configuration Release --runtime win-x64 --output ./publish# Single file executable
dotnet publish --configuration Release --runtime win-x64 --output ./publish /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishTrimmed=true
# Standard executable
dotnet publish -c Release --self-contained --runtime win-x64For detailed integration examples and advanced usage patterns, see docs/USAGE.md.
The system includes a built-in key generator accessible through the activation menu:
[DllImport(DllName, EntryPoint = "RunKeygenUI", CallingConvention = CallingConvention.Cdecl)]
public static extern void RunKeygenUI();
// Secret key generation
[DllImport(DllName, EntryPoint = "GUNK", CallingConvention = CallingConvention.Cdecl)]
public static extern void GUNK();[DllImport(DllName, EntryPoint = "TimerInitialize", CallingConvention = CallingConvention.Cdecl)]
public static extern byte LicenseTimeStatus();
// Check license status
byte status = LicenseTimeStatus();
if (status == 1)
{
Console.WriteLine("License is valid");
}| Function | Description | Parameters | Returns |
|---|---|---|---|
Initialize |
Initializes the licensing system | None | void |
RunKeygenUI |
Opens the license key generation UI | None | void |
StartLicenseChecker |
Starts background license validation | int checkIntervalSeconds |
int (instance ID) |
StopLicenseChecker |
Stops license checker instance | int instanceId |
byte (success/failure) |
LicenseTimeStatus |
Gets current license status | None | byte (status code) |
Configurations: Manages application settings and security parametersValidator: Handles license validation and decryptionJwtGenerate: Creates JWT tokens for license managementLicenseShadowCheck: Background license monitoring serviceTrial: Manages free trial functionalitySystemSecure: Provides cryptographic operations
The system uses a singleton configuration pattern. Key configuration options include:
- Product Name: Application title and branding
- JWT Security Key: For token signing and validation
- AES Keys: Hardware-derived encryption keys
- Trial Duration: Default 5 minutes with daily limits
- License Check Intervals: Configurable monitoring frequency
The system creates a unique fingerprint based on:
- System UUID
- Motherboard serial number
- CPU ID
- Combined hash for maximum uniqueness
- AES Encryption: License files encrypted with hardware-derived keys
- JWT Tokens: Signed tokens with expiration and claims validation
- File Hiding: Trial and license files marked as hidden
- Integrity Checks: Automatic validation of file modifications
- Clock Manipulation Protection: Uses UTC time for all operations
- File Integrity Monitoring: Detects license file modifications
- Runtime Validation: Continuous background license checking
- Automatic Shutdown: Application exit on tamper detection
- 5-minute trial sessions per day
- Daily usage limits to prevent abuse
- Encrypted date tracking with hardware binding
- Seamless transition to full license
- Encrypted trial data: Cannot be easily modified
- Hardware-bound keys: Prevents file transfer between machines
- Hidden file storage: Discourages casual tampering
- Application exit on tampering: Immediate shutdown if trial file is corrupted
graph TB
A[ButterAuth-Native-1] --> B[Config]
A --> C[License]
A --> D[Manager]
A --> E[Security]
A --> F[Transaction]
A --> G[Main.cs]
B --> B1[Configurations.cs]
C --> C1[JWT Components]
C --> C2[Key Generation]
C --> C3[License Management]
D --> D1[License Shadow Check]
D --> D2[Title Timer]
D --> D3[Trial System]
E --> E1[Cryptographic Keys]
E --> E2[Hardware ID]
E --> E3[System Security]
F --> F1[File Operations]
- Config: Singleton pattern for application settings
- License: JWT-based license creation and validation
- Manager: Background monitoring and trial management
- Security: Cryptographic operations and hardware binding
- Transaction: License file I/O operations
- Main: Orchestration and user interface
- Initialization: System starts and checks for existing license
- Validation: If license exists, validates signature and expiration
- Activation Menu: If no license, presents activation options
- Background Monitoring: Continuous license validation while running
- Trial Management: Handles free trial sessions with daily limits
- Security Enforcement: Monitors for tampering and unauthorized access
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow C# coding standards and conventions
- Ensure all security features are thoroughly tested
- Document any new API functions
- Test Native AOT compilation before submitting
- Validate P/Invoke signatures for cross-language compatibility
-
License Validation Fails
- Verify hardware ID hasn't changed
- Check system clock accuracy
- Ensure license hasn't expired
-
DLL Loading Issues
- Confirm target architecture (x64)
- Verify all dependencies are available
- Check Native AOT compilation settings
-
Trial System Problems
- Delete hidden trial files if corrupted
- Verify system date accuracy
- Check file permissions in temp directory
This project is licensed under the MIT License - see the LICENSE file for details.
- .NET Native AOT Documentation
- JWT.IO - JWT Token Information
- System.Management Documentation
For comprehensive integration examples, advanced patterns, and multi-language support, see the USAGE.md documentation.