unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, WinlicenseSDK;

const

LicenseHash = 'tDQpqSnQ9Kn7P8gL9I4opE25N93PUDKPIY1n2ENS7YXDdDvndY4eFVw06PQiqdL3KXhTWxRi9LaGu44wIE4AZJnRy0zOP301432l' +
              '19Lr9WZB8czQa1YYVJpiPK5M6r2xfiI26K57P7jmK82Tase8F*eccsGA2QGAQHAABACFACCUAI5VOXMLREK7ID35PNDOUBZKXX66' +
              '4GLSHQEFIAYRLEXGA6DG6VTLYYWXAHFEOCFSZU63OQ*eccpGBFQGAQHQABACFACCUAI5VOXMLREK7ID35PNDOUBZKXX664GLSHQE' +
              'FIAYRLEXGA6DG6VTLYYWXAHFEOCFSZU63OQAIKBPNH2PMKX3FIJ3LBFI4PNTO4X2GIMB4KA*eccefffbfffb020100028180ae0e' +
              'ca7149b796fe5ad18f47a1d180a2270421652915373567e7a52c14a0ed62587b3dceb68869362a4a15965d2f0f0e73275c9c' +
              '24a0723ac252b1e7ffd2bac7da529b5919844f4734454535c9b4f4af658475d7a1d0b7a566d755e0e4595e7e98ef50ae9596' +
              '65ab6962759de486b6e9c042060a2ec9add927e8bb161ef601d102030100010281801b1b6d96c81ac1f6b9f12205cf633fcb' +
              'c114c918a695c9c3d4fb440381f0f0175d5d502a65ce07c8aa3c60714af0ddc0ebd928f89e51a8889323ead60d46e5d4a11f' +
              '1231418cf5b8730ef6f7d8a8b70807745100a0cc0d1195abd9ed53f3835e8e131679e5719da5bee33ca962c27e31701c4e7b' +
              '6f1d0e219c2ac782c5f1fa330240e6a9ba177968bd063203ed8e6f55e60e4433f749c8e41b6b9b3aaf9737d54e502d49faf1' +
              '77bf8af0f6aedbaa1f4de03194b7aa694c4795264cffbd15818b12fb0240c12d515d6c3b8b4bc31360fd2e3ce734f39b33cc' +
              '64fd91b019f512e9e6af659f2402063dd6f50366ffc9df7d38d73ee30d82d7f10ea3ed10743078ba42c704a3024100604ad4' +
              '9bfe1c226516b61b12ce19befb8faf5df9987ad993976eed64a47350c919cefb8a986206ffc70b823a47ed3bbd9707018609' +
              'c90c53bbeb3b25623a0bc7024100590846f0d4da58a7f15fb41adc3dab9e070ca801f325bf08b7ddf0faa69c7e2cab8ed74b' +
              '970fd3a29c0f7196a824e452073f1fc1752aee2ee02e1ae655b29e1b0240baa0d911d3e6280cc19d3dd10a7d9eae2c66bbcb' +
              'ccd37783cd5b4754a45d4e4bb05c81fabcfce49e7dbfe74151350b2acefe9a859a73ec026a7bc8fbea7abfddfffefffe0201' +
              '00028201008daba8290bbbd82026067fed6e0d7ab9a9b01ff4607531b791f8d44f1faa2af67bfd00dfbfcaf72a5aee91db89' +
              'afc67b2b29996183be1d91cfe823b194ba4021e64aa1d757ae4a91571482847a5a2bc2c19e34dfaf572c6ed78dec63734c25' +
              'f21de5d5e1aa343aba75201816bb9232555eee1cab1f6afbd6e3e23502f140cf84592b9f85f122a339edca53c969d45e50ac' +
              '9a40215d64d3f06a6880bb1a4d6ced5248f5d260916fead0b0592da3aafcf29384a36602bd445785f8552ad5a37cb3b7bf21' +
              '7847f247823f0e378ced951a63f9cf0de7ad1a8179b53d9b4de7ff401c5dbbe0bf6bb61f19d46f050163a3766577c99aaf91' +
              '65c72f195b6dafc8d6294b02030100010282010100469019dd7be12f986fa82c1ed40275beb514ab0ddadf748874f5e5b595' +
              '557a39b3ef03f8ee3c0758fadaba1e899959f86e3ab5915aff9e15cae2daa87026469c3beaaf6aa55b03fc194df76649d4d0' +
              'd81bfd1363d89f485bdb146f09e7db25494f77f34c87aca515cb11d5bdb8e66c1896846e1613bb833d78daea41916d910e1c' +
              '7e4118e7ad5e33aa31b2520995cda34bf67469a9abce2f2959a9effd32609033426b9de346223d51730d77d6d4bff3e644f6' +
              '408edae3066f695905aa5fbf02fc44e857769d7a74693ef4113bc7f792d5a3d401e94ce2871b3e8d3914303ce30fc4b4a942' +
              'ba9ebc669e436b384ca66b3a55b4234b784cc1e67e818f428b8be9028180945d0bf930b9c64a91832cb38dd5ca0e5c842080' +
              '1686d26e1349d990272c837bafce38d6d12404f296291dc92ba4f879e8e6be301d38210746cbfafab4a51c0dff025ebbf44e' +
              '85849949ac6b74eeb030a00d3db551c3fe02416fc424ef946d19edec3234e042c17b5ed329654709f0ac8a54a1604d95dd54' +
              '0ef08f5d59f1ddb3028180f4738f21194f7b4a8ee710d8961b600beb8e0d773b79e6a61215506f9b2cf1b898689f7801a960' +
              'bb4966120b24d849109f28f07eebe78200710db1427930068decd810489e470df55a3bc1634b7dbc9b8b7d3fad2e259cdd5f' +
              '304fc5f78650d02f3ad3bc143cb81c2420a3b959d4d16c64e93b5a0524471e14a5154acc322a09028180899d68fec2007f7a' +
              '2950c804e059de6ac5cbd4ad9ab781b692739cb7466ed6a2c2a6813858939577426b6ef26b6641082b4ce43a92cfbe6b1673' +
              '1c20b1b0b8be0ebcaf0c9e06bb780c0b3740111d5916314f36ded9b1f70936932a17ac963b40a2dcc49121372a6a79c15a13' +
              '53fa5760638b2e88ba4e791680290881e96d1c5b0281801e9502780a9995fc1aeaaf81d92dad937031c25f835259d7b6f571' +
              'adb4c527ac876cb75ea51e929a7bb1485a9a8e707da2dbd5529ba2c7f1d432f9552ea2227fc8fcb2f4d2d062dfaa1d45b16d' +
              '755a8e3f2239402a40cc6229917ab972a11c251f73859fc70c5da02fa8e1b2c3994b65fb2dee9df17cbb64f9023a2ab46726' +
              '390281801305f34876519da3d519241aa099ef86291237439db6f2771a4b4f7a0a94c5d4da65fd9fa2833054ff4f2b3f1322' +
              '74690c8efbb848963aa88378bc3bf783fab2203ed46bb9fda95df2d4357d41b4c1eca79e03224134195a4815f0d7685b6ecf' +
              'cd974f9dec1d7579b4d9a5cf86ba3187c5f2ed9cabeb7bb8856c68b41d893c85';




type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    NameEdit: TEdit;
    OrgEdit: TEdit;
    HardIdEdit: TEdit;
    CustomEdit: TEdit;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    NumDaysEdit: TEdit;
    NumExecEdit: TEdit;
    ExpDate: TDateTimePicker;
    EnableDateCheck: TCheckBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    Label4: TLabel;
    FileNameEdit: TEdit;
    GenFileKey: TButton;
    GroupBox5: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    RegistryEdit: TEdit;
    Button2: TButton;
    Edit3: TEdit;
    RegValueEdit: TEdit;
    LicRegEdit: TEdit;
    RadioGroup1: TRadioGroup;
    Button3: TButton;
    GroupBox6: TGroupBox;
    GenStaticSmartKey: TButton;
    SmartEdit: TEdit;
    TextKeyMemo: TMemo;
    GenDynamicSmartKey: TButton;
    procedure GenFileKeyClick(Sender: TObject);
    procedure EnableDateCheckClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure GenStaticSmartKeyClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure GenDynamicSmartKeyClick(Sender: TObject);
  private
     { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.GenFileKeyClick(Sender: TObject);
var
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey, i: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  ExpDateSysTime: SYSTEMTIME;
  NumDays, NumExec: integer;
  KeyFile: FILE OF AnsiChar;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
    DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLGenLicenseFileKey(LicenseHash, pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, LicenseKeyBuff) ;

 // save generated key in user file

 AssignFile(KeyFile, FileNameEdit.Text);

 Rewrite(KeyFile);

 for i:= 0 TO SizeKey-1 DO
   Write(KeyFile, LicenseKeyBuff[i]);

 CloseFile(KeyFile);

  MessageBox(0, 'A License key file has been generated', 'License Key Generator SDK', MB_OK);

end;

procedure TForm1.EnableDateCheckClick(Sender: TObject);
begin

 if EnableDateCheck.State =  cbChecked  then
    ExpDate.Enabled := True
 else
    ExpDate.Enabled := False;


end;

procedure TForm1.Button3Click(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLGenLicenseTextKey(LicenseHash, pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, LicenseKeyBuff) ;
  TextKeyMemo.Text := LicenseKeyBuff;

end;

procedure TForm1.GenStaticSmartKeyClick(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..1000] of AnsiChar;
  SizeKey: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);
                     
  SizeKey := WLGenLicenseSmartKey(LicenseHash, pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, LicenseKeyBuff) ;
  SmartEdit.Text := LicenseKeyBuff;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ExpDateSysTime: SYSTEMTIME;
  LicenseKeyBuff: ARRAY[0..4000] of AnsiChar;
  SizeKey, i: integer;
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  NumDays, NumExec: integer;
  KeyFile: FILE OF AnsiChar;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  if EnableDateCheck.Checked = False  then
    ZeroMemory(Addr(ExpDateSysTime), sizeof(ExpDateSysTime))
  else
   DateTimeToSystemTime(ExpDate.Date, ExpDateSysTime);

  SizeKey := WLGenLicenseRegistryKey(LicenseHash, pName, pOrg, pCustom, pHardId, NumDays, NumExec, ExpDateSysTime, 0, 0, 0, PAnsiChar('HKEY_LOCAL_MACHINE\' + RegistryEdit.Text), PAnsiChar(RegValueEdit.Text), LicenseKeyBuff) ;

 // save generated key in user file

 AssignFile(KeyFile, LicRegEdit.Text);

 Rewrite(KeyFile);

 for i:= 0 TO SizeKey-1 DO
   Write(KeyFile, LicenseKeyBuff[i]);

 CloseFile(KeyFile);

  MessageBox(0, 'A License key file has been generated', 'License Key Generator SDK', MB_OK);

end;

procedure TForm1.GenDynamicSmartKeyClick(Sender: TObject);
var                  
  pName: PAnsiChar;
  pOrg: PAnsiChar;
  pCustom: PAnsiChar;
  pHardId: PAnsiChar;
  LicenseKeyBuff: ARRAY[0..1000] of AnsiChar;
  LicenseFeatures: sLicenseFeatures;
  SizeKey: Integer;
  NumDays, NumExec: integer;

begin

  if length(NameEdit.Text) = 0 then
    pName := nil
  else
    pName := PAnsiChar(AnsiString(NameEdit.Text));

  if length(OrgEdit.Text) = 0 then
    pOrg := nil
  else
    pOrg := PAnsiChar(AnsiString(OrgEdit.Text));

  if length(CustomEdit.Text) = 0 then
    pCustom := nil
  else
    pCustom := PAnsiChar(AnsiString(CustomEdit.Text));

  if length(HardIdEdit.Text) = 0 then
    pHardId := nil
  else
    pHardId := PAnsiChar(AnsiString(HardIdEdit.Text));

  if length(NumDaysEdit.Text) = 0 then
    NumDays := 0
  else
    NumDays := StrToInt(NumDaysEdit.Text);

  if length(NumExecEdit.Text) = 0 then
    NumExec := 0
  else
    NumExec := StrToInt(NumExecEdit.Text);

  // initialize LicenseFeatures

  FillChar(LicenseFeatures, SizeOf(sLicenseFeatures), 0);
  LicenseFeatures.cb := SizeOf(sLicenseFeatures);

  // set LicenseFeatures according to GUI settings

  LicenseFeatures.NumDays := NumDays;
  LicenseFeatures.NumExec := NumExec;

  if EnableDateCheck.Checked then
    DateTimeToSystemTime(ExpDate.Date, LicenseFeatures.InstallDate);

  // Generate Dynamic SmartKey and display it on GUI

  SizeKey := WLGenLicenseDynSmartKey(LicenseHash, pName, pOrg, pCustom, pHardId, LicenseFeatures, LicenseKeyBuff);
  SmartEdit.Text := LicenseKeyBuff;

end;

end.
