# Legacy algorithms

Before standardizing the hardware ID algorithms, different LicenseSpring SDKs used to compute slightly different hardware IDs. Each platform that SDKs run on had a default algorithm and alternative algorithms.

### Default Algorithm

{% stepper %}
{% step %}

### Windows

The default hardware ID algorithm uses WMI to fetch Model, Manufacturer, Name, SerialNumber of the motherboard, processor and the system disk. Afterwards, it encodes them to provide a unique string that represents the current device.
{% endstep %}

{% step %}

### Linux

The default device id reads the machine id from the `/etc/machine-id` file. This file contains the unique machine ID of the local system that is set during installation or boot. If this id is not found, it tries to read the `/var/lib/dbus/machine-id` file. If it still fails to get the id, it writes a generated UUID.
{% endstep %}

{% step %}

### MacOS

The C++ SDK uses the `gethostuuid()` system call to get a unique identifier of the device. The .Net SDK gets the `IOPlatformUUID` value. The Swift SDK gets the machine UUID.
{% endstep %}

{% step %}

### iOS

The Swift SDK gets `UIDevice.current.identifierForVendor`.
{% endstep %}
{% endstepper %}

### Windows Algorithms

#### C++ SDK

{% stepper %}
{% step %}

### Gen2

Gen2 algorithm is similar to the default algorithm. It is safer and shorter than default. This algorithm retrieves the Manufacturer and SerialNumber of the motherboard, CPU name and id, and disk model and serial number. This algorithm can be useful for air gap licenses.
{% endstep %}

{% step %}

### WinCSProductId

An alternative algorithm for Windows. It gets the UUID of the Windows machine using Computer System Product Id through WMI.
{% endstep %}

{% step %}

### WinCryptographyId

An algorithm for Windows that doesn't use WMI. It gets Microsoft Cryptography MachineGuid from the Windows registry.
{% endstep %}
{% endstepper %}

#### .Net SDK

{% stepper %}
{% step %}

### Gen1

Includes minor improvements for ID calculation on Windows; on other platforms it is the same as Default.
{% endstep %}

{% step %}

### Gen2 and Gen3

Safer device id algorithms on Windows; on other platforms they are the same as Default. Gen3 is a shorter form that can be useful for air gap licenses.
{% endstep %}

{% step %}

### WinAlternative

This algorithm tries to get Microsoft Cryptography MachineGuid from the Windows registry. If this request fails or the .Net Framework version is earlier than 4.0, it tries to get the UUID of the Windows machine using Computer System Product Id.
{% endstep %}
{% endstepper %}

### Cloud Platform Algorithms

{% stepper %}
{% step %}

### CloudPlatformsId

Useful when the software runs on Azure, AWS or GCP. It is a good option when the application will be used only on these platforms. If the application can be installed on other platforms as well, the AutoId algorithm should be used.
{% endstep %}

{% step %}

### AutoId

Uses different approaches depending on your platform. If the application is running on Azure, AWS or GCP, it is the same as CloudPlatformsId; otherwise it is the same as Default.
{% endstep %}

{% step %}

### AutoIdWinCloud

Also uses different platform-dependent approaches. If the application is running on Azure, AWS or GCP, it is the same as CloudPlatformsId; otherwise it is the same as WinCSProductId. This algorithm should only be used on Windows computers.
{% endstep %}
{% endstepper %}

### Hardware ID Usage

#### Configuration

After choosing an algorithm, set it in ExtendedOptions or LicenseSpringConfiguration.

{% tabs %}
{% tab title="C++" %}
{% code title="C++" %}

```cpp
LicenseSpring::ExtendedOptions options;
options.setDeviceIdAlgorithm(AutoId);
```

{% endcode %}
{% endtab %}

{% tab title=".NET (C#)" %}
{% code title="C#" %}

```csharp
var options = new ExtendedOptions();
options.DeviceIdAlgorithm = DeviceIDAlgorithm.AutoId;
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code title="Swift" %}

```swift
configuration.hardwareID = generateMyOwnCustomID()
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code title="Java" %}

```java
LicenseSpringConfiguration config = LicenseSpringConfiguration.builder()
  .identityProvider(HardwareIdStrategy.AUTO_HARDWARE_ID)
  .build();
```

{% endcode %}
{% endtab %}
{% endtabs %}

The .NET SDK allows specifying the timeout for cloud platforms ID requests. It is useful when AutoId takes too long on a regular machine. This value is specified in milliseconds; the default is 200.

```csharp
options.CloudIdRequestTimeout = 100;
```

The SDK allows overriding hardware ID. For instance, you can use the MAC address as the hardware ID:

{% tabs %}
{% tab title="C++" %}
{% code title="C++" %}

```cpp
LicenseSpring::ExtendedOptions options;
options.setHardwareID(options.getNetworkInfo().mac());
```

{% endcode %}
{% endtab %}

{% tab title=".NET (C#)" %}
{% code title="C#" %}

```csharp
var configuration = new LicenseSpring.Configuration();
var options = new LicenseSpring.ExtendedOptions();
options.HardwareID = configuration.MACAddress;
configuration.ExtendedOptions = options;
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code title="Go" %}

```go
// Go SDK v2
lm_config := license_manager.LicenseManagerBasicConfiguration{
				OAuth:             false,
				ApiKey:            "your-api-key",
				SharedKey:         "your-shared-key",
				ProductCode:       "your-product-code",
				AuthData:          auth.FromKey("LICENSE-KEY"),
			}

lm, _ := license_manager.NewLicenseManager(
    lm_config,
    license_manager.WithHardwareId("your-HW-ID"),
)
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code title="Java" %}

```java
LicenseSpringConfiguration config = LicenseSpringConfiguration.builder()
  .identityProvider(customIdentityProvider)
  .build();
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/tutorials/best-practices/hardware-id-generation/legacy-algorithms.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
