home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FLXKEY10.ZIP / MAKEKEY2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  5.7 KB  |  139 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to create *)
  4. (* an encrypted registration-key using "embedded" encryption-codes.   *)
  5. (*                                                                    *)
  6. (* NOTE: Before you can compile this program, you must first          *)
  7. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  8. (*       the two "random" encryption-code binary data files. Then     *)
  9. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  10. (*       these two binary data files to "object" format files.        *)
  11. (**********************************************************************)
  12.  
  13. program MakeFlxKeyDemo2;
  14. uses
  15.   FlxKey;
  16.  
  17. type          (* 20 character string definition.                      *)
  18.   st20    = string[20];
  19.  
  20.               (* 20 character string-pointer definition.              *)
  21.   st20Ptr = ^st20;
  22.  
  23. var           (* This variable is used to check for errors returned   *)
  24.               (* by CreateFlxKey routine.                             *)
  25.   ErrorCode : word;
  26.  
  27.               (* 2 encryption-code string-pointers.                   *)
  28.   Ecode1Ptr,
  29.   Ecode2Ptr  : st20Ptr;
  30.  
  31.               (* Full path/filename of the encrypted registration-key *)
  32.               (* file to be created.                                  *)
  33.   RegKeyName : st79;
  34.  
  35.               (* This variable is used to pass the user-data to the   *)
  36.               (* CreateFlxKey routine.                                *)
  37.   TempKeyRec : FlxRec;
  38.  
  39.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  40.  
  41.               (* "Fake" procedure that contains first encryption-code *)
  42.               (* string.                                              *)
  43.   procedure Ecode1Data; external;
  44.   {$L ECODE1.OBJ}
  45.  
  46.               (* "Fake" procedure that contains second encryption-    *)
  47.               (* code string.                                         *)
  48.   procedure Ecode2Data; external;
  49.   {$L ECODE2.OBJ}
  50.  
  51.   {$F-}       (* Turn off "FAR" declaration.                          *)
  52.  
  53.               (* Main program execution block.                        *)
  54. BEGIN
  55.               (* Initialize the encryption-code pointers to their     *)
  56.               (* string data.                                         *)
  57.   Ecode1ptr := addr(Ecode1Data);
  58.   Ecode2ptr := addr(Ecode2Data);
  59.  
  60.               (* Clear the temporary key-record variable.             *)
  61.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  62.  
  63.               (* Assign data to temporary key-record.                 *)
  64.   with TempKeyRec do
  65.     begin
  66.               (* 20 char space is available for first-name.           *)
  67.       FirstName := 'John';
  68.  
  69.               (* 30 char space is available for last-name.            *)
  70.       LastName  := 'Smith';
  71.  
  72.               (* 30 char space is available for Address1.             *)
  73.       Address1  := '1234 AnyPlace Road,';
  74.  
  75.               (* 30 char space is available for Address2.             *)
  76.       Address2  := 'BigCity BigPlace,';
  77.  
  78.               (* 30 char space is available for Address3.             *)
  79.       Address3  := 'BigCountry, BigZip';
  80.  
  81.               (* 20 char space is available for application-name.     *)
  82.       AppName   := 'Amazing Program';
  83.  
  84.               (* Version can be assigned any valid word data.         *)
  85.       Version   := 310;
  86.  
  87.               (* Serial can be assigned any valid longint data.       *)
  88.       Serial    := 1234567890;
  89.  
  90.               (* Date can be assigned any valid "packed" date/time.   *)
  91.               (* If a value of 0 is assigned to Date, CreateFlxKey    *)
  92.               (* routine will assign the current date/time to this    *)
  93.               (* variable in "packed" date/time format. Use TP's      *)
  94.               (* standard "PackTime" and "UnPackTime" routines to     *)
  95.               (* manipulate this data.                                *)
  96.       Date      := 0;
  97.  
  98.               (* Access level can be assigned a number from 0..65,535 *)
  99.       Access    := 1234
  100.     end;
  101.  
  102.               (* Filename for the encrypted registration-key to be    *)
  103.               (* created.                                             *)
  104.   RegKeyName := 'DEMO2.KEY';
  105.  
  106.               (* Create encrypted registration-key using the data     *)
  107.               (* assigned to TempKeyRec.                              *)
  108.   CreateFlxKey(TempKeyRec, Ecode1Ptr^, Ecode2Ptr^, RegKeyName, ErrorCode);
  109.  
  110.               (* Move cursor down one line.                           *)
  111.   writeln;
  112.  
  113.               (* Check for errors.                                    *)
  114.   case (ErrorCode AND $FF) of
  115.      0 : writeln(' Sucessful key creation! No errors.');
  116.      1 : writeln(' Error! One or more encryption-codes are blank.');
  117.      2 : writeln(' Error! Filename for registration-key file is blank.');
  118.  
  119.               (* I/O error!                                           *)
  120.     16 : begin
  121.            writeln(' I/O error = ', (ErrorCode shr 8));
  122.  
  123.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  124.               (* as there many types of errors to check for.          *)
  125.            case (ErrorCode shr 8) of
  126.                2 : writeln(' File not found.');
  127.                3 : writeln(' Path not found.');
  128.                4 : writeln(' Too many files open.');
  129.                5 : writeln(' File access denied.');
  130.              101 : writeln(' Disk write error.');
  131.              103 : writeln(' File not open');
  132.              150 : writeln(' Disk is write-protected')
  133.            end  (* case (ErrorCode shr 8) of                          *)
  134.          end
  135.   end         (* case (ErrorCode AND $FF) of                          *)
  136. END.
  137.  
  138.  
  139.