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

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from encrypted registration-key file.                    *)
  5. (**********************************************************************)
  6.  
  7. program ReadFlxKeyDemo1;
  8. uses
  9.   Crt,
  10.   FlxKey;
  11.  
  12. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  13.               (* the difference in days between the current date and  *)
  14.               (* the date encrypted into the registration-key file.   *)
  15.   DaysOld,
  16.  
  17.               (* This variable is used to check for errors returned   *)
  18.               (* by ReadFlxKey routine.                               *)
  19.   ErrorCode : word;
  20.  
  21.               (* Encryption-code strings used to create encrypted     *)
  22.               (* registration-key file.                               *)
  23.   Ecode1,
  24.   Ecode2 : st100;
  25.  
  26.               (* This is the full path/filename of the encrypted      *)
  27.               (* registration-key file to be decrypted.               *)
  28.   RegKeyName : st79;
  29.  
  30.               (* Record variable to hold the data decrypted from the  *)
  31.               (* encrypted registration-key file.                     *)
  32.   TempKeyRec : FlxRec;
  33.  
  34.               (* Main program execution block.                        *)
  35. BEGIN
  36.               (* Clear the temporary key-record variable.             *)
  37.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  38.  
  39.               (* Assign encryption-code strings to be used to decrypt *)
  40.               (* encrypted registration-key data.                     *)
  41.   Ecode1 := 'Apple';
  42.   Ecode2 := 'Orange';
  43.  
  44.               (* Full path/filename for the encrypted registration-   *)
  45.               (* key file to be decrypted.                            *)
  46.   RegKeyName := 'DEMO1.KEY';
  47.  
  48.               (* Decrypt the registration-key file, and retrieve it's *)
  49.               (* data.                                                *)
  50.               (* NOTE: A 10 second delay and message are present in   *)
  51.               (*       the un-registered copy of the FlxKey unit.     *)
  52.   ReadFlxKey(Ecode1, Ecode2, RegKeyName, TempKeyRec, DaysOld, ErrorCode);
  53.  
  54.               (* Clear the screen.                                    *)
  55.   clrscr;
  56.   writeln;
  57.  
  58.               (* Check for errors.                                    *)
  59.   if (ErrorCode <> 0) then
  60.     case (ErrorCode AND $FF) of
  61.        1 : writeln(' Error! One or more encryption-codes are blank.');
  62.        2 : writeln(
  63.                 ' Error! Filename for registration-key file is blank.');
  64.        3 : writeln(' Error! Registration-key file is corrupt.');
  65.  
  66.               (* I/O error!                                           *)
  67.       16 : begin
  68.              writeln(' I/O error = ', (ErrorCode shr 8));
  69.  
  70.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  71.               (* as there are many types of errors to check for.      *)
  72.              case (ErrorCode shr 8) of
  73.                  2 : writeln(' File not found.');
  74.                  3 : writeln(' Path not found.');
  75.                  4 : writeln(' Too many files open.');
  76.                  5 : writeln(' File access denied.');
  77.                100 : writeln(' Disk read error.');
  78.                103 : writeln(' File not open')
  79.              end  (* case (ErrorCode shr 8) of                        *)
  80.            end
  81.     end       (* case (ErrorCode AND $FF) of                          *)
  82.   else
  83.               (* Else NO errors occurred.                             *)
  84.     begin
  85.               (* Display the decrypted registration-key data.         *)
  86.       writeln('Key is ', DaysOld, ' days old');
  87.       writeln;
  88.       with TempKeyRec do
  89.         begin
  90.           writeln(' FirstName    = ', FirstName);
  91.           writeln(' LastName     = ', LastName);
  92.           writeln(' Address1     = ', Address1);
  93.           writeln(' Address2     = ', Address2);
  94.           writeln(' Address3     = ', Address3);
  95.           writeln(' AppName      = ', AppName);
  96.           writeln(' Version      = ', Version);
  97.           writeln(' Serial Num   = ', Serial);
  98.  
  99.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  100.               (* can be used to manipulate "packed date" data.        *)
  101.           writeln(' Packed Date  = ', Date);
  102.  
  103.           writeln(' Access Level = ', Access)
  104.         end
  105.     end
  106. END.
  107.  
  108.  
  109.