There are many methods to encrypt files, but there are some shortcomings in the traditional file-based encryption methods. For example, the headache of cryptographic technology, complex full-text encryption/decryption algorithms, and the generation of spam files. Here I will introduce you to a new idea of file encryption. Right-click a file in Win 95/98 to view its properties. The file creation time, modification time, and access time are listed. This information is generally set automatically by the operating system (that is, by Dos/Windows, etc.) and will not be easily modified by users. With this feature, we can implement a very concealed encryption technology.
Encryption principle:
Replace the original file time with the specified time information.
Decryption principle:
Compare the time information of the encrypted file with the specific time information. If the time information is the same, the file is legal. If the time information is different, the file is an expired or pirated software.
The preceding section briefly introduces how to modify the time attribute of a file. This method can be used for simple software encryption. For example, if an archived file is stored after a software or game is executed, the operating system automatically sets the modification time of the file, users with a little experience can find the last modified file by using the "Find file" function in Windows. If the file is a file that records the password or user information (in many cases, this is actually the case), the consequences are simply unimaginable. In addition, if you set the file creation, modification time, and access time as appropriate, for example, to maintain a certain interval between the three, it can be used as a good means of encryption. When running the main software, you only need to dynamically check whether the file time meets the specific requirements to know whether the software has expired or belongs to pirated software, so as to achieve the purpose of encrypting and protecting the software, and does not generate junk files.
The following describes the implementation methods:
The FindFirst function in Delphi can be used to obtain the attribute record of a file. The FindData field in the record records detailed file time information. The time information in FindData cannot be directly obtained. The CovFileDate function in the source program in this article can be used to convert the file time format. The time needed to set the file is more complex. You can use the DataTimePicker component in Delphi to complete this complex operation. You can use four DataTimePicker components to set the File Creation Time and modification time. Note: The file access time is replaced by the modification time. When using the following example, add four DataTimePicker components to your Form. Kind in the first and third DataTimePicker components is set to dtkDate, Kind in the second and fourth DataTimePicker components is set to dtkTime, and DateMode is set to dmUpDown.
Note: The time range for modifying files starts from January 1, September 19, 1792 AD. The maximum value can be 2999 AD or higher.