A tutorial on storing and collecting device information in the C++ SDK.
Storing the License File on a Database
Although a default location is specified for the local license file, It is possible to adjust the location of the local license file. Storing the license file on a database, on a windows registry or remotely are all possibilities within LicenseSpring’s C++ SDK. In this guide we will explore encrypting this license file, adding the license file to a database and the differences between the file storage classes in the SDK.
Note: This guide assumes that SQLite3 has been properly installed on the readers’ device and basic knowledge of SQL. For more information about SQLite, refer to their documentation.
- Encrypting the License File
- Adding the License File to the Database
- Differences between FileStorage, FileStorageBase, and FileStorageEx
Encrypting the License File:
Within the LicenseStorage.h interface, encryption and decryption of the license file is performed through running elementary functions within the C++ SDK. Encryption occurs when the license is activated and initially stored, using activateLicense() in LicenseManager.h.
Decryption of the license file is done when either reloadLicense() or getCurrentLicense() are called, both of which can be found in BaseManager.h.
Note: loadLicense() and saveLicense() found in the LicenseFileStorage.h do NOT encrypt/decrypt the license file, they only read and write. Encryption is done through the activation and retrieval of the license file.
Adding the License File to the Database:
The first step is to create an instance of the LicenseStorage interface to interact with the database. This tutorial’s code sample shows an implementation using SQLite3, a database engine written in the C language. After creating the inherited class and implementing loadLicense(), saveLicense(), and clear() we need to replace the default file location. In order to do so, when creating the LicenseManager object we need to pass in a second parameter. This second parameter adjusts the storage location for local license, which by default is saved in a file.
Note: Encryption is performed outside of these methods, loadLicense and saveLicense do not need to encrypt/decrypt.
Differences between LicenseFileStorageBase, LicenseFileStorage, and LicenseFileStorageEx:
LicenseFileStorageBase is a base class that saves licenses in a file and implements the LicenseStorage interface. This class does not use any techniques for file access synchronization so it is not thread safe.
The LicenseFileStorage Class is derived from the LicenseFileStorageBase class. This is the default license storage type. File operations of this class are thread safe.
LicenseFileStorageEx is also derived from the LicenseFileStorageBase class. It is an enhanced license file storage type used for interprocess use. It uses a boost named mutex for synchronization. File operations of this class are thread and process safe.