> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/go-sdk/v2/handler/storage.md).

# Storage

### Storage

The `Storage` interface is designed to be a flexible and extensible abstraction for any storage backend used in the SDK. It provides a minimal contract that allows upper layers (like the license handler) to persist license data securely, regardless of the actual implementation (file system, database, remote service, etc.).

#### Storage Interface

{% code title="storage.go" %}

```go
type Storage interface {
	SetCryptoProvider(cryptoProvider crypto_provider.CryptoProvider)
	GetCryptoProvider() crypto_provider.CryptoProvider
}
```

{% endcode %}

These setter and getter functions ensure that every `Storage` implementation uses a `CryptoProvider` to handle encryption and decryption of sensitive license data. This guarantees that all stored data—regardless of format or location—is encrypted with a consistent mechanism.

### File Storage

The SDK includes a built-in implementation of Storage called FileStorage, which persists encrypted data locally to disk. This interface extends Storage and defines all methods required to manage license files, guard files, and any encrypted metadata.

#### FileStorage Interface

{% code title="file\_storage.go" %}

```go
type FileStorage interface {
	Storage
	DataDirectory() (string, error)
	LicenseFileName(string) string
	SaveLicense(data interface{}) error
	LoadLicense(fileName string) (license_file.LicenseFile, error)
	ClearLocalLicenseData(productCode string) error
	OfflineGuardPath() (string, error)
	StoreEncryptedData(path string, data interface{}) error
	LoadEncryptedData(path string, out interface{}) error
	LoadGuardFile(password string) (types.OfflineActivationGuard, error)
	SaveGuardFile(guard interface{}) error
	RemoveFile(file_path string) error
}
```

{% endcode %}

This interface provides all the required capabilities for securely storing and retrieving license and guard files using encryption. It can be used as-is or replaced with a custom storage implementation.

### Crypto Provider

The CryptoProvider interface is responsible for encryption and decryption of sensitive data before it is saved or after it is loaded. It is designed to be pluggable, allowing you to implement your own encryption scheme if needed.

#### CryptoProvider Interface

{% code title="crypto\_provider.go" %}

```go
type CryptoProvider interface {
	Encrypt(license_file interface{}) (interface{}, error)
	Decrypt(data interface{}) (interface{}, error)
	SetKey(password string)
	GetKey() (string, error)
}
```

{% endcode %}

Any implementation of this interface must be able to securely encrypt and decrypt data using a key that can be set or retrieved. The SDK comes with a `DefaultCryptoProvider` implementation that uses AES encryption.

### Default Implementations

Both FileStorage and CryptoProvider come with default implementations:

* DefaultFileStorage – uses local disk paths to save and retrieve encrypted license data.
* DefaultCryptoProvider – performs AES encryption and decryption using a key you provide.

You can use them directly when creating a LicenseHandler, or omit them entirely and let the SDK initialize the defaults automatically.

Example usage:

{% code title="example\_usage.go" %}

```go
cp := crypto_provider.DefaultCryptoProvider{}
cp.SetKey("my-encryption-key")

storage := data_handler.DefaultFileStorage{}
storage.SetCryptoProvider(&cp)

cfg := license_handler.LicenseHandlerConfig{
	ApiKey:      "your-api-key",
	SharedKey:   "your-shared-key",
	ProductCode: "my-product",
	AuthData:    auth.FromKey("LICENSE_KEY"),
	Storage:     storage,
}
```

{% endcode %}

This setup allows you to override either the storage mechanism or the crypto logic without touching the SDK’s licensing logic.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.licensespring.com/sdks/go-sdk/v2/handler/storage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
