File Activation Delphi 2016 -
procedure SignLicenseFile(const LicenseFile: string; const PrivateKey: TArray<Byte>); var LicenseStream: TFileStream; License: TLicenseData; DataToSign: TBytes; Signature: TBytes; begin // Populate License fields (UserName, ProductCode, ExpirationDate, HardwareIDHash, FeatureMask) // ... // Create binary representation of data EXCLUDING the signature field DataToSign := BytesOf(License.UserName) + BytesOf(License.ProductCode) + BytesOf(License.ExpirationDate) + BytesOf(License.FeatureMask) + BytesOf(License.HardwareIDHash);
uses System.SysUtils, System.Classes, System.Hash, Winapi.Windows, ActiveX, ComObj; function GetHardwareID: string; var WbemLocator, WbemServices, WbemObjectSet, WbemObject: OleVariant; MacAddress, CpuId, VolumeId: string; HashBytes: TBytes; begin // Initialize COM for WMI CoInitialize(nil); try WbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); WbemServices := WbemLocator.ConnectServer('localhost', 'root\CIMV2', '', ''); File Activation Delphi 2016
// Retrieve MAC Address WbemObjectSet := WbemServices.ExecQuery('SELECT MACAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True'); if WbemObjectSet.Count > 0 then MacAddress := WbemObjectSet.ItemIndex(0).MACAddress; For brevity, assume you have a SignData function
type TLicenseData = packed record Magic: Integer; // Constant identifier, e.g., $4C494345 ('LICE') Version: Byte; // License format version UserName: array[0..99] of Char; ProductCode: TGUID; ExpirationDate: TDateTime; FeatureMask: Int64; HardwareIDHash: array[0..63] of Char; // Base64 of machine hash Signature: array[0..255] of Byte; // RSA signature (2048-bit) end; Your activation server (or a simple Delphi tool you keep in-house) signs the file. You will need a private key (e.g., from OpenSSL). For brevity, assume you have a SignData function that uses RSA-SHA256. This will be serialized, signed, and saved to disk
begin Application.Initialize; Application.Title := 'MyApp'; if not IsLicenseValid(ExtractFilePath(ParamStr(0)) + 'license.key') then begin ShowMessage('Invalid or missing license file. Application will now exit.'); Exit; end;
// Retrieve Volume Serial of C: WbemObjectSet := WbemServices.ExecQuery('SELECT VolumeSerialNumber FROM Win32_LogicalDisk WHERE DeviceID="C:"'); if WbemObjectSet.Count > 0 then VolumeId := WbemObjectSet.ItemIndex(0).VolumeSerialNumber; // Combine and hash HashBytes := THashSHA2.GetHashBytes(MacAddress + CpuId + VolumeId); Result := TNetEncoding.Base64.EncodeBytesToString(HashBytes); finally CoUninitialize; end; end; Define a record that holds license data. This will be serialized, signed, and saved to disk.