# Local License File

After license activation the SDK creates an encrypted file that contains license information. This article provides information about the local license file and data location.

See also: [**Security and Cryptographic Providers**](https://docs.licensespring.com/sdks/tutorials/best-practices/broken-reference) for more information about license encryption and [**Custom License Storage**](https://docs.licensespring.com/sdks/tutorials/best-practices/broken-reference) for information about alternative ways to save license.

{% stepper %}
{% step %}

### Prerequisites

* Completed the [**Getting Started**](https://docs.licensespring.com/sdks/tutorials/best-practices/broken-reference) Tutorial, specifically:
  * Initialized `LicenseManager` (or `LicenseHandler`) with your configuration using the appropriate settings.
  * Created a `LicenseID` using either `LicenseID::fromKey` or `LicenseID::fromUser` function, depending on the activation method you prefer.
  * Implemented basic license management, including license activations, deactivations, and both online and local license checks.
    {% endstep %}
    {% endstepper %}

### Default Data Location

The location of the license file depends on the operating system in use.

On Windows, the default SDK data location is: **{SystemDrive}:/Users/{UserName}/AppData/Local/LicenseSpring/{ProductCode}**

On Linux, the default SDK data location is: **HOME/.LicenseSpring/LicenseSpring/{ProductCode}**

On macOS, the default SDK data location is: **\~/Library/Application Support/LicenseSpring/{ProductCode}**

To get the location and name of local license file use the following method:

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

```cpp
auto dataLocation = licenseManager->dataLocation();
auto fileName = licenseManager->licenseFileName();
```

{% endtab %}

{% tab title="C#" %}

```csharp
var path = LicenseManager.GetInstance().DataLocation;
var name = LicenseManager.GetInstance().LicenseFileName;
```

{% endtab %}

{% tab title="Swift" %}

```swift
let file = manager.licenseFile
```

{% endtab %}

{% tab title="Python" %}

```python
manager = LicenseManager(conf)
folder_path = manager.data_location()
file_name = manager.license_file_name()

print("data folder path: ",folder_path)
print("data file name: ",file_name)
```

{% endtab %}

{% tab title="Java" %}

```java
String DEFAULT_DIR = "LicenseSpring";
String DEFAULT_LICENSE_PATH = Paths.get(DEFAULT_DIR, productCode, LICENSE_KEY)
  .toAbsolutePath()
  .toString();
```

{% endtab %}
{% endtabs %}

### Changing Data Location

#### Using License Manager

To change the location of local license file, use:

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

```cpp
licenseManager->setDataLocation( L"my/license/path" );
licenseManager->setLicenseFileName( L"MyLicense.lic" );
```

{% endtab %}

{% tab title="C#" %}

```csharp
LicenseManager.GetInstance().DataLocation = "my/data/location";
LicenseManager.GetInstance().LicenseFileName = "MyLicense.lic";
```

{% endtab %}

{% tab title="Python" %}

```python
manager.set_data_location("my/data/location")
manager.set_license_file_name("cool_name")
```

{% endtab %}

{% tab title="Java" %}

```java
LicenseSpringConfiguration config = LicenseSpringConfiguration.builder()
  .licenseFilePath("<customLicenseFilePath>")
  .build();
```

{% endtab %}
{% endtabs %}

You can also delete all files created by SDK using the clearLocalStorage method:

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

```cpp
licenseManager->clearLocalStorage();
```

{% endtab %}

{% tab title="C#" %}

```csharp
LicenseManager.GetInstance().ClearLocalStorage();
```

{% endtab %}

{% tab title="Swift" %}

```swift
try manager.clearLocalStorage()
```

{% endtab %}

{% tab title="Python" %}

```python
manager.clear_local_storage()
```

{% endtab %}

{% tab title="Java" %}

```java
licenseManager.clearLocalStorage();
```

{% endtab %}
{% endtabs %}

#### Using Extended Options

If preferred, it is also possible to adjust the location of the local license file before the creation of the `LicenseManager` object in the C++ SDK. This is possible by constructing the `ExtendedOptions` object with the license file path as the lone parameter:

```cpp
ExtendedOptions options = ExtendedOptions(licenseFilePath);
```

Alternatively, it is possible to set the license file path after the `ExtendedOptions` using the setLicenseFilePath() method as follows:

```cpp
options.setLicenseFilePath(licenseFilePath);
```

### License File Corruption

In case the license file gets corrupted during encryption or writing, local license data could be lost. To prevent this, you can check if the local license file is corrupted either on every license file write through a flag in `ExtendedOptions`, or whenever you want.

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

```cpp
// check if license file is corrupted
bool isCorrupted = licenseManager::isLicenseFileCorrupted();

// enable check on every license file write
ExtendedOptions extendedOptions;
extendedOptions.enableLicenseCorruptionCheck( true );
```

{% endtab %}

{% tab title="Python" %}

```python
manager.is_license_file_corrupted()
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Note: This introduces a runtime overhead due to decrypting an encrypted string.
{% endhint %}

### Usage Scenarios

Changing the data location allows to implement different scenarios, making the license file acessible by certain users and applications.

#### Sharing the License Between Users

The default data location makes the license available for the current user only. To make it available for all users of the device, set a path that all users can acess, e.g.:

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

```cpp
licenseManager->setDataLocation( L"C:\Users\Public\{Product Code}" );
```

{% endtab %}

{% tab title="C#" %}

```csharp
LicenseManager.GetInstance().DataLocation = "C:\Users\Public\{Product Code}";
```

{% endtab %}

{% tab title="Swift" %}

```swift
configuration.licenseDirectoryPath = URL(fileURLWithPath: "/Users/Shared/shared_location")
```

{% endtab %}

{% tab title="Python" %}

```python
manager = LicenseManager(conf)

manager.set_data_location(f"C:\Users\Public\{Product Code}"
```

{% endtab %}

{% tab title="Java" %}

```java
LicenseSpringConfiguration config = LicenseSpringConfiguration.builder()
  .licenseFilePath("C:/Users/Public/{Product Code}")
  .build();
```

{% endtab %}
{% endtabs %}

#### Sharing the License Between Applications

When you have multiple apps that use LicenseSpring, you can provide a single license for all products. If the user activates a license for one product, the other apps could access the license without license reactivation. To achieve this, make the data location path not product-dependent:

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

```cpp
licenseManager->setDataLocation( L"C:/Users/{UserName}/AppData/Local/LicenseSpring/{CompanyName}" );
```

{% endtab %}

{% tab title="C#" %}

```csharp
LicenseManager.GetInstance().DataLocation = "C:/Users/{UserName}/AppData/Local/LicenseSpring/{CompanyName}";
```

{% endtab %}

{% tab title="Swift" %}

```swift
configuration.licenseDirectoryPath = URL(fileURLWithPath: "/Users/xxx/shared_location")
```

{% endtab %}

{% tab title="Python" %}

```python
manager = LicenseManager(conf)

manager.set_data_location(f"C:/Users/{UserName}/AppData/Local/LicenseSpring/{CompanyName}")
```

{% endtab %}

{% tab title="Java" %}

```java
LicenseSpringConfiguration config = LicenseSpringConfiguration.builder()
  .licenseFilePath("C:/Users/{UserName}/AppData/Local/LicenseSpring/{CompanyName}")
  .build();
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Note: Currently license files created by different SDKs are not compatible. Make sure to store the license files created by different SDKs separately.
{% endhint %}

{% hint style="danger" %}
LocalLicenseException will be thrown if the SDK attempts to read a license file created by another SDK. It also occurs when the local license file is damaged or cannot be loaded or saved.
{% endhint %}
