SDKs
...
v2
License Handler
Storage
7min
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 type storage interface { 	setcryptoprovider(cryptoprovider crypto provider cryptoprovider) 	getcryptoprovider() crypto provider cryptoprovider } 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 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 } 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 type cryptoprovider interface { 	encrypt(license file interface{}) (interface{}, error) 	decrypt(data interface{}) (interface{}, error) 	setkey(password string) 	getkey() (string, error) } 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 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, } this setup allows you to override either the storage mechanism or the crypto logic without touching the sdk’s licensing logic