# KeyNexus .NET SDK

Official .NET SDK for KeyNexus License Management System.

## Installation

```bash
dotnet add package KeyNexus.SDK
```

Or via NuGet Package Manager:
```
Install-Package KeyNexus.SDK
```

## Quick Start

```csharp
using KeyNexus;

// Initialize client
var client = new KeyNexusClient(
    appId: "app_xxxxxxxxxxxx",
    secretKey: "sk_xxxxxxxxxxxxxxxxxxxx"
);

// Validate license
var result = await client.ValidateLicenseAsync("XXXXX-XXXXX-XXXXX-XXXXX");

if (result.Success)
{
    Console.WriteLine($"✅ License valid!");
    Console.WriteLine($"Type: {result.Data.License.Type}");
    Console.WriteLine($"Expires: {result.Data.License.ExpiresAt}");
}
else
{
    Console.WriteLine($"❌ Error: {result.Message}");
}
```

## Features

- ✅ Automatic HWID generation using hardware information
- ✅ License validation
- ✅ Username/password authentication
- ✅ Session management
- ✅ Full async/await support
- ✅ Compatible with .NET Standard 2.0+

## Supported Platforms

- .NET Framework 4.6.1+
- .NET Core 2.0+
- .NET 5, 6, 7, 8
- Xamarin
- Unity (with .NET Standard 2.0)

## Examples

### Initialize Application

```csharp
var initResult = await client.InitializeAsync(version: "1.0.0");
if (initResult.Success)
{
    Console.WriteLine("App initialized successfully");
}
```

### Validate License

```csharp
var result = await client.ValidateLicenseAsync("XXXXX-XXXXX-XXXXX-XXXXX");
if (result.Success)
{
    var license = result.Data.License;
    
    if (license.Type == "lifetime")
    {
        Console.WriteLine("Lifetime license - no expiration");
    }
    else if (license.DaysLeft.HasValue)
    {
        Console.WriteLine($"License expires in {license.DaysLeft} days");
    }
}
```

### Login with Password

```csharp
var loginResult = await client.LoginWithPasswordAsync("username", "password");
if (loginResult.Success)
{
    Console.WriteLine($"Welcome {loginResult.Data.User.Username}!");
}
```

### Get User Info

```csharp
var userResult = await client.GetUserInfoAsync();
if (userResult.Success)
{
    var user = userResult.Data;
    Console.WriteLine($"Email: {user.Email}");
    Console.WriteLine($"Subscription expires: {user.SubscriptionExpiry}");
}
```

### Hardware ID

```csharp
// Get auto-generated HWID
string hwid = client.GetHWID();
Console.WriteLine($"Your HWID: {hwid}");

// Or generate manually
string manualHwid = KeyNexusClient.GenerateHWID();

// Set custom HWID
client.SetHWID("custom-hwid-here");
```

## Error Handling

```csharp
try
{
    var result = await client.ValidateLicenseAsync(licenseKey);
    
    if (!result.Success)
    {
        // Handle specific errors
        switch (result.Message)
        {
            case var msg when msg.Contains("HWID"):
                Console.WriteLine("This license is locked to another device");
                break;
            case var msg when msg.Contains("expired"):
                Console.WriteLine("License has expired");
                break;
            default:
                Console.WriteLine($"Error: {result.Message}");
                break;
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Unexpected error: {ex.Message}");
}
```

## Documentation

Full documentation available at: https://keynexus.es/docs

## License

MIT License - see LICENSE file for details
