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

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from encrypted registration-key file, using "embedded"   *)
  5. (* encryption-code strings.                                           *)
  6. (*                                                                    *)
  7. (* NOTE: Before you can compile this program, you must first          *)
  8. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  9. (*       the two "random" encryption-code binary data files. Then     *)
  10. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  11. (*       these two binary data files to "object" format files.        *)
  12. (**********************************************************************)
  13.  
  14. program ReadFlxKeyDemo2;
  15. uses
  16.   Crt,
  17.   FlxKey;
  18.  
  19. type          (* 20 character string definition.                      *)
  20.   st20    = string[20];
  21.  
  22.               (* 20 character string-pointer definition.              *)
  23.   st20Ptr = ^st20;
  24.  
  25. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  26.               (* the difference in days between the current date and  *)
  27.               (* the date encrypted into the registration-key file.   *)
  28.   DaysOld,
  29.  
  30.               (* This variable is used to check for errors returned   *)
  31.               (* by ReadFlxKey routine.                               *)
  32.   ErrorCode : word;
  33.  
  34.               (* Encryption-code string-pointers, used to decrypt the *)
  35.               (* data in the encrypted registration-key file.         *)
  36.   Ecode1Ptr,
  37.   Ecode2Ptr  : st20Ptr;
  38.  
  39.               (* This is the full path/filename of the encrypted      *)
  40.               (* registration-key file to be decrypted.               *)
  41.   RegKeyName : st79;
  42.  
  43.               (* Record variable to hold the data decrypted from the  *)
  44.               (* encrypted registration-key file.                     *)
  45.   TempKeyRec : FlxRec;
  46.  
  47.   {$F+}       (* Declare the following two procedures as "FAR".       *)
  48.  
  49.               (* "Fake" procedure that contains first encryption-code *)
  50.               (* string.                                              *)
  51.   procedure Ecode1Data; external;
  52.   {$L ECODE1.OBJ}
  53.  
  54.               (* "Fake" procedure that contains second encryption-    *)
  55.               (* code string.                                         *)
  56.   procedure Ecode2Data; external;
  57.   {$L ECODE2.OBJ}
  58.  
  59.   {$F-}       (* Turn off "FAR" declaration.                          *)
  60.  
  61.               (* Main program execution block.                        *)
  62. BEGIN
  63.               (* Initialize the encryption-code string pointers to    *)
  64.               (* their data.                                          *)
  65.   Ecode1ptr := addr(Ecode1Data);
  66.   Ecode2ptr := addr(Ecode2Data);
  67.  
  68.               (* Clear the temporary key-record variable.             *)
  69.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  70.  
  71.               (* Full path/filename for the encrypted registration-   *)
  72.               (* key file to be decrypted.                            *)
  73.   RegKeyName := 'DEMO2.KEY';
  74.  
  75.               (* Decrypt the registration-key file, and retreive it's *)
  76.               (* data.                                                *)
  77.               (* NOTE: A 10 second delay and message are present in   *)
  78.               (*       the un-registered copy of the FlxKey unit.     *)
  79.   ReadFlxKey(Ecode1Ptr^, Ecode2Ptr^, RegKeyName, TempKeyRec, DaysOld,
  80.              ErrorCode);
  81.  
  82.               (* Clear the screen.                                    *)
  83.   clrscr;
  84.   writeln;
  85.  
  86.               (* Check for errors.                                    *)
  87.   if (ErrorCode <> 0) then
  88.     case (ErrorCode AND $FF) of
  89.        1 : writeln(' Error! One or more encryption-codes are blank.');
  90.        2 : writeln(
  91.                 ' Error! Filename for registration-key file is blank.');
  92.        3 : writeln(' Error! Registration-key file is corrupt.');
  93.  
  94.               (* I/O error!                                           *)
  95.       16 : begin
  96.              writeln(' I/O error = ', (ErrorCode shr 8));
  97.  
  98.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  99.               (* as there are many types of errors to check for.      *)
  100.              case (ErrorCode shr 8) of
  101.                  2 : writeln(' File not found.');
  102.                  3 : writeln(' Path not found.');
  103.                  4 : writeln(' Too many files open.');
  104.                  5 : writeln(' File access denied.');
  105.                100 : writeln(' Disk read error.');
  106.                103 : writeln(' File not open')
  107.              end  (* case (ErrorCode shr 8) of                        *)
  108.            end
  109.     end       (* case (ErrorCode AND $FF) of                          *)
  110.   else
  111.               (* Else NO errors occurred.                             *)
  112.     begin
  113.               (* Display the decrypted registration-key data.         *)
  114.       writeln('Key is ', DaysOld, ' days old');
  115.       writeln;
  116.       with TempKeyRec do
  117.         begin
  118.           writeln(' FirstName    = ', FirstName);
  119.           writeln(' LastName     = ', LastName);
  120.           writeln(' Address1     = ', Address1);
  121.           writeln(' Address2     = ', Address2);
  122.           writeln(' Address3     = ', Address3);
  123.           writeln(' AppName      = ', AppName);
  124.           writeln(' Version      = ', Version);
  125.           writeln(' Serial Num   = ', Serial);
  126.  
  127.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  128.               (* can be used to manipulate "packed date" data.        *)
  129.           writeln(' Packed Date  = ', Date);
  130.  
  131.           writeln(' Access Level = ', Access)
  132.         end
  133.     end
  134. END.
  135.  
  136.  
  137.