File Transparent Encryption and Decryption Method and System Based on Ciphertext Misappropriation
Through the ciphertext appropriation technology, the ciphertext is misappropriated to plaintext for use in non-buffered write operations, which solves the problems of file size increase and code complexity in the existing technology, and achieves the compatibility and stability of file encryption.
Patent Information
- Application Number
- CN202210549949.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-20
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2042-05-20
AI Technical Summary
The prior art requires filling plaintext when encrypting files to meet the requirements of block cipher algorithms, resulting in an increase in file size and complex adaptation to applications, affecting the stability and maintenance difficulty of the file system.
The ciphertext appropriation method is adopted. During non-buffered write operations, the ciphertext of the penultimate block is used to the plaintext of the last block, completing the filling process, ensuring that the file size remains unchanged after encryption, simplifying code logic and reducing the adaptation needs of the application.
It realizes encryption without changing the file size, reduces the impact on the file system, simplifies code logic, avoids separate adaptation to applications, and improves system compatibility and stability.
Smart Images

Figure CN115203733B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of file encryption and decryption, and particularly to a method and system for transparent file encryption and decryption based on ciphertext appropriation. Background Art
[0002] The statements in this section merely mention the background art related to the present invention and do not necessarily constitute prior art.
[0003] Block cipher algorithms such as AES, DES, etc. require the plaintext size to be an integer multiple of the block size. If the plaintext does not meet this requirement, a padding block needs to be added, and the ciphertext size will increase accordingly. When applied to the transparent encryption and decryption driver of general Windows, it is often necessary to add an extra padding block to the plaintext for encryption when the file system driver writes disk data, and then increase the file size (EOF) to write the padded ciphertext to the disk.
[0004] At this time, the general Windows transparent encryption and decryption driver will choose to increase the file size during buffered write operations or when the application itself modifies the file size. This implementation method is difficult, and the driver needs to adapt to the application, resulting in complex code logic and affecting the later maintenance of the code. Summary of the Invention
[0005] To solve the deficiencies of the prior art, the present invention provides a method and system for transparent file encryption and decryption based on ciphertext appropriation. When encrypting a file during non-buffered write operations, the block cipher uses the ciphertext stealing method to appropriate the ciphertext encrypted in the penultimate block for use as the plaintext of the last block to complete the padding process, without the need for additional padding, ensuring that the encrypted ciphertext is the same size as the original file and does not require an increase in file size. Compared with general transparent encryption and decryption methods, the method of the present invention encrypts files without changing the file size, has little impact on the file system, has simple code logic, and does not require separate adaptation of the application.
[0006] In the first aspect, the present invention provides a method for transparent file encryption and decryption based on ciphertext appropriation;
[0007] The method for transparent file encryption and decryption based on ciphertext appropriation includes:
[0008] Obtain the file to be processed;
[0009] Determine whether the file to be processed is a target extension file. If not, end the process; if so, proceed to the next step;
[0010] Determine whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation;
[0011] Determine whether the process of the file to be processed is an authorized process. If it is, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute.
[0012] In a second aspect, the present invention provides a file transparent encryption and decryption system based on ciphertext embezzlement;
[0013] A file transparent encryption and decryption system based on ciphertext embezzlement includes:
[0014] An acquisition module, which is configured to: acquire a file to be processed;
[0015] A first judgment module, which is configured to: judge whether the file to be processed is a target extension file. If not, end; if so, proceed to the next step;
[0016] A second judgment module, which is configured to: judge whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation;
[0017] A third judgment module, which is configured to: judge whether the process of the file to be processed is an authorized process. If it is, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute.
[0018] Compared with the prior art, the beneficial effects of the present invention are:
[0019] When the process has a tendency to write files with specific extensions (such as txt, docx), the files are automatically encrypted. When an authorized process wants to read the ciphertext file, it is automatically decrypted, and when the file is modified, it is automatically encrypted. An unauthorized process does not decrypt, displays the ciphertext, and is not allowed to modify the ciphertext. When encrypting a file during a non-buffered write operation, the block cipher uses the method of ciphertext embezzlement to embezzle the ciphertext encrypted by the penultimate block for use in the plaintext of the last block to complete the padding process, without the need for additional padding, ensuring that the size of the encrypted ciphertext is the same as that of the original file and does not require an increase in the file size. Compared with general transparent encryption and decryption methods, the method of the present invention encrypts files without changing the file size, has little impact on the file system, has simple code logic, and does not require separate adaptation of application programs. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings forming a part of the present invention are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention.
[0021] Figure 1 It is a flowchart of the method for the first embodiment;
[0022] Figure 2 It is the flowchart of the write operation for the first embodiment;
[0023] Figure 3 It is the flowchart of the read operation for the first embodiment;
[0024] Figure 4(a) is the flowchart of the ciphertext misappropriation encryption for the first embodiment;
[0025] Figure 4(b) is the flowchart of the ciphertext misappropriation decryption for the first embodiment;
[0026] Figure 5 It is the diagram of the unmodified data with the data size of the penultimate write operation being one sector size;
[0027] Figure 6 It is the diagram of the modified data with the data size of the penultimate write operation being one sector size;
[0028] Figure 7 It is the diagram of the unmodified data with the data size of the penultimate write operation being greater than one sector size;
[0029] Figure 8 It is the diagram of the modified data with the data size of the penultimate write operation being greater than one sector size;
[0030] Figure 9 It is the flowchart of the data processing for the penultimate read operation;
[0031] Figure 10 It is the flowchart of the data processing for the last but one read operation; Specific implementation manners
[0032] It should be noted that the following detailed description is exemplary and is intended to provide further illustration of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.
[0033] It should be noted that the terms used herein are only for the purpose of describing specific implementation manners and are not intended to limit the exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular forms are also intended to include the plural forms. In addition, it should be understood that the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0034] Without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0035] All data acquisition in this embodiment is based on compliance with laws, regulations, and user consent, and is a legal application of data.
[0036] Embodiment 1
[0037] This embodiment provides a file transparent encryption and decryption method based on ciphertext misappropriation;
[0038] As Figure 1 shown, the file transparent encryption and decryption method based on ciphertext misappropriation includes:
[0039] S101: Obtain the file to be processed;
[0040] S102: Determine whether the file to be processed is a target extension file. If not, end; if so, proceed to the next step;
[0041] S103: Determine whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation;
[0042] S104: Determine whether the process of the file to be processed is an authorized process. If so, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute.
[0043] Further, the file to be processed in S101 specifically refers to: a text file that the operating system is to write to the disk.
[0044] Further, in S102, it is determined whether the file to be processed is a target extension file. Among them, the target extension file refers to: a type of file with a set file extension set in the minifilter, such as a.txt file,.doc file, etc.;
[0045] Further, in S104, it is determined whether the process corresponding to the file to be processed is an authorized process. Among them, the authorized process refers to: a process that is allowed to decrypt an encrypted file set in the minifilter.
[0046] Further, the encryption process for the write operation specifically includes:
[0047] S103a1: Whether the size of the disk space occupied by the file to be processed is less than the block size specified by the block cipher algorithm. If so, use other streaming algorithms to encrypt the file to be processed and end the process; if not, proceed to S103a2; the other streaming algorithms include: the RC4 algorithm or the A5 / 1 algorithm;
[0048] S103a2: If the last two plaintext blocks of the file to be processed are not adjacent, determine whether the current write operation ends with the penultimate plaintext block; if so, process the penultimate write operation and end the process; if not, proceed to S103a3;
[0049] S103a3: Determine whether the size of the file to be processed is greater than the block size and the size of the data written in the current write operation is less than the block size. If true, process the last write operation and end the process. If not true, proceed to S103a4;
[0050] S103a4: Determine whether the size of the data written in the current write operation is aligned with the block size. If so, encrypt the file to be processed using a block cipher algorithm and end the process; if not, encrypt the file to be processed using the ciphertext stealing method and end the process.
[0051] When encrypting using a block cipher algorithm, the plaintext is divided into multiple blocks of equal length, and then each block is encrypted using the same key to obtain ciphertext blocks.
[0052] When encrypting using a block cipher algorithm, if the data size and the block size are not aligned, the last block is padded. Ciphertext stealing uses the ciphertext encrypted from the penultimate block for the plaintext of the last block to complete the padding process.
[0053] Further, the specific steps for processing the penultimate write operation include:
[0054] S103a21: If the data size of the penultimate write operation is equal to the size of a sector, save the data of the penultimate write operation in the Stream Context, record the write offset and the size of the data of this block in the Stream Context, directly intercept the I / O data request packet IRP and return successfully, and set the return value IoStatus.Information to the size of the write operation data in the I / O data request packet before modification;
[0055] S103a22: If the data size of the penultimate write operation is greater than the size of a sector, subtract the data of the size of a sector from the data size of the penultimate write operation, save the subtracted data in the Stream Context, and record the write offset and size of this subtracted data in the Stream Context; encrypt the remaining data using a block cipher algorithm, modify the size of the data of the write operation in the I / O data request packet, and allow the I / O data request packet IRP to be sent to the file system driver.
[0056] S103a23: When the file system driver finishes the write operation and returns to the minifilter, restore the return value IoStatus.Information to the write operation data size in the I / O data request packet before it was modified.
[0057] Among them, the file system driver is a device driver that implements a certain file system.
[0058] Furthermore, the processing of the penultimate write operation specifically includes the following steps:
[0059] S103a31: Add data of one sector size saved in the Stream Context before the data of the penultimate write operation to make the last two plaintext blocks of the file to be processed adjacent, and encrypt the concatenated data using the ciphertext embezzlement method;
[0060] S103a32: Retrieve the saved write offset and the data size of the write operation from the Stream Context, modify the write offset and the data size of the write operation in the I / O data request packet to the current write offset and the data size of the write operation, and allow the I / O data request packet IRP (I / O Request Packets) to be sent to the file system driver;
[0061] S103a33: When the file system driver finishes the write operation and returns to the minifilter, restore the return value IoStatus.Information to the write operation data size in the I / O data request packet before it was modified.
[0062] Furthermore, the decryption processing of the read operation specifically includes:
[0063] S103b1: Whether the size of the disk space occupied by the file to be processed is less than the block size specified by the block cipher algorithm; if so, use other streaming algorithms to decrypt the file to be processed and end the processing; if not, proceed to S103b2; the other streaming algorithms include: RC4 algorithm or A5 / 1 algorithm;
[0064] S103b2: If the last two ciphertext blocks of the file to be processed are not adjacent, determine whether the current read operation ends with the penultimate ciphertext block; if so, process the penultimate read operation and end the processing; if not, proceed to S103b3;
[0065] S103b3: Determine whether it holds that the size of the file to be processed is greater than the block size and the size of the disk space occupied by the current read operation is less than the block size. If it holds, process the penultimate read operation and end the processing. If it does not hold, proceed to S103b4;
[0066] S103b4: Determine whether the data size of the current read operation is aligned with the block size. If it is, decrypt the file to be processed using the block cipher algorithm and end the process; if not, decrypt the file to be processed using the ciphertext embezzlement method and end the process.
[0067] Further, process the penultimate read operation; specifically including:
[0068] S103b21: Use a non-reentrant non-buffered read operation to read the last misaligned ciphertext data block of the file from the disk, reapply for a block of memory, splice the ciphertext of the penultimate read operation and the separately read ciphertext into a block of data, and decrypt the spliced data using the ciphertext embezzlement method;
[0069] S103b22: Copy the plaintext with the same offset and data size as the penultimate read operation back into the memory allocated by the requester of the read operation.
[0070] A non-reentrant non-buffered read operation means that the read operation will not enter the minifilter again, and the data is directly read from the disk by the file system driver without passing through the buffer manager.
[0071] Further, process the last read operation; specifically including:
[0072] S103b31: Use a non-reentrant non-buffered read operation to read the ciphertext data of the penultimate read operation, reapply for a block of memory, splice the separately read ciphertext and the ciphertext of the last read operation into a block of data, and decrypt the spliced data using the ciphertext embezzlement method;
[0073] S103b32: Copy the plaintext with the same offset and data size as the last read operation back into the memory allocated by the requester of the read operation.
[0074] This application decrypts files with misaligned block sizes using the ciphertext embezzlement method; when the file size is less than one block, other stream encryption algorithms are selected for decryption; when the file size is aligned with the block size, the block cipher algorithm is directly used for decryption.
[0075] When using ciphertext embezzlement in non-buffered read operations, and the last two non-buffered read operations are exactly separated between the last two ciphertext blocks of the file. When the file minifilter intercepts the IRP sent to the file system driver, modify the last two non-buffered read operations respectively.
[0076] A non-buffered read operation is a read operation in which the file system driver directly reads data from the disk without passing through the buffer manager.
[0077] This application is mainly used for data anti-disclosure. For example, a company wants to prevent employees from leaking important data. However, if files and data are encrypted and decrypted every time, it is too complex and troublesome. Therefore, generally, a transparent encryption method is used so that employees' normal office software cannot detect that the data has been encrypted. For non-office software, especially communication software that may cause data leakage, it will not be able to decrypt and view the ciphertext.
[0078] This application provides a block cipher encryption and decryption method in the Windows file system that does not require expanding the file size. The method includes: when the file size and block size are not aligned, using the ciphertext embezzlement method for encryption and decryption; when the file size is less than one block, selecting other stream encryption algorithms for encryption and decryption; directly using the block cipher algorithm for encryption and decryption when the file size and block size are aligned.
[0079] In non-buffered paging write operations, use ciphertext embezzlement. When the penultimate and last write operations are exactly separated between the last two plaintext blocks of the file, subtract one sector from the data of the penultimate write operation, save it in the StreamContext, add this sector before the data of the last write operation, make the last two blocks adjacent, and use the ciphertext embezzlement method to encrypt the spliced data.
[0080] In non-buffered read operations, use ciphertext embezzlement. When the penultimate and last read operations are exactly separated between the last two ciphertext blocks of the file, use non-reentrant non-buffered read functions to read the ciphertext to be spliced for the two read operations respectively, then use the ciphertext embezzlement method to decrypt the spliced data, and then copy the plaintext with the same offset and data size as this read operation back to the memory allocated by the requester of the read operation.
[0081] The encryption process is shown in Figure 4(a). Pn-1 and Pn are plaintext. The data size of the former is aligned with the block size, and the latter needs to be filled. Cn-1 and Cn are ciphertext, and C’ is the ciphertext of the size to be filled for Pn. The ciphertext after encrypting Pn-1 is divided into two parts. One part is moved backward to become Cn, and the other part C’ and Pn are filled and encrypted to become ciphertext Cn-1. Finally, it becomes a block of data Cn-1Cn. As can be seen from the above, the length of this block of data is the same as the length of the original plaintext.
[0082] The decryption process is shown in Figure 4(b). Cn-1 and Cn are ciphertext. The data size of the former is aligned with the block size, and the latter needs to be filled. Pn-1 and Pn are plaintext, and C’ is the ciphertext of the size to be filled for Cn. The plaintext after decrypting Cn-1 is divided into two parts. One part is moved backward to become Pn, and the other part C’ and Cn are filled and decrypted to become plaintext Pn-1. Finally, it becomes a block of data Pn-1Pn. It can be seen that ciphertext embezzlement can encrypt and decrypt data normally.
[0083] In this way, it is possible to encrypt, decrypt, and handle files with misaligned block sizes using the ciphertext embezzlement method.
[0084] Ciphertext embezzlement requires the file to be at least larger than one block size. Therefore, for files smaller than one block, other stream encryption algorithms are selected for encryption and decryption, such as Figure 2 、 Figure 3 for the encryption and decryption process.
[0085] When the file size is aligned with the block size, the block cipher algorithm can be directly used for encryption and decryption without ciphertext embezzlement, such as Figure 2 、 Figure 3 for the encryption and decryption process.
[0086] Because the Windows file system requires that the data size and write offset of non-buffered write operations must be aligned with the sector size (this value is usually 0x200), and it does not allow the file size to be extended during non-buffered paged write operations, the file size is usually extended during buffered write operations or the function is directly called to modify the file size before the write operation. When the driver or buffer manager performs non-buffered paged write operations, the data beyond the file size will be truncated.
[0087] In this case, if the last two operations of the non-buffered paged write operation of a file are exactly separated between the last two plaintext blocks of the file, and the actual data size of the last write operation is less than the block size at this time (although the size of the write operation is sector-aligned, the data beyond the file size is truncated), the problem of non-adjacent last two plaintext blocks of the file will occur in ciphertext embezzlement.
[0088] According to whether the data size of the penultimate write operation is one sector size, it is divided into two processing methods, namely Figure 5 、 Figure 6 and Figure 7 、 Figure 8 . Briefly speaking, the processing method is to subtract one sector from the data of the penultimate write operation and save it in the Stream Context, add this sector to the data of the last write operation to make the last two blocks adjacent, and then use the ciphertext embezzlement method to encrypt the concatenated data. In addition, the data size and write offset of the two write operations need to be modified separately.
[0089] The data size of the penultimate write operation is one sector size; such as Figure 5It is a normal data write. The data to be written is a block of data with a size of 0x207. Due to the requirements of non-buffered write operations, this block of data needs to be aligned with the sector, so the total memory size written is 0x400. This data is written in two times. The size of the data written in the penultimate write is 0x200, and the size of the data actually written in the last write is 0x7 (the suffix of 0x1F9 will be truncated). The last plaintext block of 0x7 and the penultimate plaintext block (at an offset of 1F0 and a size of 0x10) are not adjacent, so ciphertext misappropriation cannot be used.
[0090] Therefore, use StreamContext to save the data of the entire sector size of the penultimate write operation, and record the offset and size.
[0091] Figure 6 For the data processed by the present invention, since there is no data to be written in the penultimate write operation, directly return FLT_PREOP_COMPLETE, and the return value IoStatus.Information is restored to the write operation data size in the I / O data request packet before modification.
[0092] Add the data of one sector saved by StreamContext to the data of the last write operation, encrypt the spliced data using the method of ciphertext misappropriation, then modify the data size (ByteCount) and write offset (StartingVbo) of the write operation, and send the ciphertext as a whole to the file system driver, which is written to the disk by the file system driver.
[0093] Finally, as Figure 2 , at PostWrite, restore the return value IoStatus.Information to the write operation data size in the I / O data request packet before modification.
[0094] The data size of the penultimate write operation is greater than one sector size:
[0095] Figure 7 It is a normal data write. Use StreamContext to save the data of the last sector size of the penultimate write operation, and record the write offset and the data size of the write operation.
[0096] Figure 8 For the data processed by the present invention, subtract the size of one sector from the data size (ByteCount) of the penultimate write operation, and then directly encrypt the remaining 0x200 data using the block cipher algorithm and send it to the file system driver, which is written to the disk by the file system driver.
[0097] Add the data of one sector saved by the StreamContext before the data of the penultimate write operation, encrypt the concatenated data using the ciphertext embezzlement method, then modify the data size and write offset of the write operation, and send the ciphertext as a whole to the file system driver, which writes it to the disk.
[0098] Finally, as Figure 2 shown, during PostWrite, restore the return values IoStatus.Information of the two write operations to the write operation data sizes in the I / O data request packet before modification.
[0099] The Windows file system requires that the data size and read offset of non-buffered read operations must be aligned with the sector size (this value is usually 0x200). Therefore, as Figure 9 shown, if the data size of the read operation is 0x400, which exceeds the file size (0x207), the excess data will be truncated. Similarly, if there are two non-buffered read operations, as Figure 9 、 Figure 10 shown, and they are exactly separated between the last two ciphertext blocks of the file. At this time, the actual data size of the last read operation is less than the block size, and ciphertext embezzlement decryption cannot be used. The processing method is: use a non-reentrant non-buffered read function to read the ciphertext to be concatenated, then use the ciphertext embezzlement method to decrypt the concatenated data, and then copy the plaintext that is the same as the read offset and read operation data size back to the memory allocated by the requester of the read operation.
[0100] Processing of the penultimate read operation: As Figure 9 shown, use the FltReadFileEx function, set the non-buffered flag, and the FileObject is non-reentrant. Read out the last misaligned block, concatenate it with the previous ciphertext, and decrypt the whole using ciphertext embezzlement. Then copy 0x200 of the plaintext back to the memory allocated by the requester of the read operation.
[0101] Processing of the last read operation: As Figure 10 shown, use the FltReadFileEx function, set the non-buffered flag, and the FileObject is non-reentrant. Read out the ciphertext of the second-to-last sector of 0x200, concatenate it with the ciphertext of 0x7, and decrypt the whole using ciphertext embezzlement. Then copy 0x7 of the plaintext back to the memory allocated by the requester of the read operation.
[0102] The transparent encryption and decryption minifilter using ciphertext embezzlement allows the file size not to be aligned with the block size of the block cipher algorithm. Therefore, there is no need to add a block of padding to the file, ensuring that the ciphertext size is the same as the original file size. As a result, there is no need to separately expand the file size in the minifilter, and the code implementation logic is simple, eliminating the need for separate adaptation for the application later.
[0103] The transparent encryption and decryption of files provides a new method for handling file sizes, achieving the same function as traditional methods in a way that minimizes interference with the file system, which is more in line with the principles of file filtering drivers and improves the overall compatibility and stability of the system.
[0104] Embodiment 2
[0105] This embodiment provides a file transparent encryption and decryption system based on ciphertext embezzlement;
[0106] A file transparent encryption and decryption system based on ciphertext embezzlement includes:
[0107] An acquisition module configured to: acquire a file to be processed;
[0108] A first judgment module configured to: judge whether the file to be processed is a target extended file. If not, end; if so, proceed to the next step;
[0109] A second judgment module configured to: judge whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation;
[0110] A third judgment module configured to: judge whether the process of the file to be processed is an authorized process. If so, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute.
[0111] It should be noted here that the above acquisition module, first judgment module, second judgment module, and third judgment module correspond to steps S101 to S104 in Embodiment 1. The examples and application scenarios implemented by the above modules and the corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1 above. It should be noted that the above modules, as part of the system, can be executed in a computer system such as a set of computer executable instructions.
[0112] In the above embodiments, the descriptions of each embodiment have their own emphases. For parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0113] The proposed system can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of the above-mentioned modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0114] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A file transparent encryption and decryption method based on ciphertext misappropriation, characterized in that Including: Obtain the file to be processed; Judge whether the file to be processed is a target extension file, where the target extension file refers to a type of file with a set file extension set in the minifilter. If not, end; if so, proceed to the next step; Judge whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation; Judge whether the process of the file to be processed is an authorized process. If so, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute; The encryption processing of the write operation specifically includes: Whether the size of the disk space occupied by the file to be processed is less than the block size specified by the block cipher algorithm. If so, use other streaming algorithms to encrypt the file to be processed and end the processing; if not, proceed to the next step; If the last two plaintext blocks of the file to be processed are not adjacent, judge whether the current write operation ends with the penultimate plaintext block. If so, process the penultimate write operation and end the processing; if not, proceed to the next step; Judge whether the size of the file to be processed is greater than the block size and the size of the data written in the current write operation occupies less than the block size. If it holds, process the last write operation and end the processing. If it does not hold, proceed to the next step; Judge whether the size of the data written in the current write operation is aligned with the block size. If so, use the block cipher algorithm to encrypt the file to be processed and end the processing; if not, use the ciphertext stealing method to encrypt the file to be processed and end the processing; The specific steps of processing the last write operation include: Add data of one sector size saved in the Stream Context before the data of the last write operation to make the last two plaintext blocks of the file to be processed adjacent, and use the ciphertext stealing method to encrypt the spliced data; Retrieve the saved write offset and the size of the write operation data from the Stream Context, modify the write offset and the size of the write operation data in the I / O data request packet to the current write offset and the size of the write operation data, and allow the I / O data request packet to be sent to the file system driver; When the file system driver completes the write operation and returns to the minifilter, restore the return value IoStatus.Information to the size of the write operation data in the I / O data request packet before modification.
2. The file transparent encryption and decryption method based on ciphertext misappropriation according to claim 1, wherein, The specific steps of processing the penultimate write operation include: If the size of the data of the penultimate write operation is equal to the size of one sector, save the data of the penultimate write operation in the stream context Stream Context, record the write offset and the size of the write operation data of this block in the stream context Stream Context, directly intercept the I / O data request packet IRP and return successfully, and set the return value IoStatus.Information to the size of the write operation data in the I / O data request packet before modification; If the data size of the penultimate write operation is greater than the size of one sector, subtract the data of one sector size from the data size of the penultimate write operation, save the subtracted data in the Stream Context, and record the write offset and size of the subtracted data in the Stream Context; encrypt the remaining data using the block cipher algorithm, modify the data size of the write operation in the I / O data request packet, and allow the I / O data request packet IRP to be sent to the file system driver; When the file system driver completes the write operation and returns to the minifilter, restore the return value IoStatus.Information to the data size of the write operation in the I / O data request packet before modification.
3. The file transparent encryption and decryption method based on ciphertext embezzlement according to claim 1, characterized in that, The decryption process for the read operation specifically includes: Whether the size of the disk space occupied by the file to be processed is less than the block size specified by the block cipher algorithm; if so, use other streaming algorithms to decrypt the file to be processed and end the process; if not, proceed to the next step; If the last two ciphertext blocks of the file to be processed are not adjacent, determine whether the current read operation ends with the penultimate ciphertext block; if so, process the penultimate read operation and end the process; if not, proceed to the next step; Determine whether the size of the file to be processed is greater than the block size and the size of the disk space occupied by the file in the current read operation is less than the block size. If it holds, process the last read operation and end the process. If it does not hold, proceed to the next step; Determine whether the data size of the current read operation is aligned with the block size. If so, decrypt the file to be processed using the block cipher algorithm and end the process; if not, decrypt the file to be processed using the ciphertext stealing method and end the process.
4. The file transparent encryption and decryption method based on ciphertext misappropriation according to claim 3, characterized in that, The processing of the penultimate read operation specifically includes: Use a non-reentrant non-buffered read operation to read the last unaligned ciphertext data block of the file from the disk, reapply for a block of memory, splice the ciphertext of the penultimate read operation and the separately read ciphertext into a block of data, and decrypt the spliced data using the ciphertext stealing method; Copy the plaintext with the same offset and data size as the penultimate read operation back to the memory allocated by the requester of the read operation.
5. The file transparent encryption and decryption method based on ciphertext misappropriation according to claim 3, characterized in that, The processing of the last read operation specifically includes: Use a non-reentrant non-buffered read operation to read the ciphertext data of the penultimate read operation, reapply for a block of memory, splice the separately read ciphertext and the ciphertext of the last read operation into a block of data, and decrypt the spliced data using the ciphertext stealing method; Copy the plaintext with the same offset and data size as the last read operation back to the memory allocated by the requester of the read operation.
6. The file transparent encryption and decryption method based on ciphertext misappropriation according to claim 1, characterized in that Determine whether the process of the file to be processed is an authorized process, where an authorized process refers to a process that is set in the minifilter and is allowed to decrypt the encrypted file.
7. A file transparent encryption and decryption system based on ciphertext misappropriation, characterized in that, It includes: An acquisition module, which is configured to: acquire the file to be processed; The first judgment module is configured to: determine whether the file to be processed is a target extension file, where the target extension file refers to a type of file with a set file extension set in the minifilter. If not, the process ends; if so, proceed to the next step; The second judgment module is configured to: determine whether the file has been encrypted. If so, proceed to the next step; if not, encrypt the write operation; The third judgment module is configured to: determine whether the process of the file to be processed is an authorized process. If so, encrypt the write operation and decrypt the read operation; if not, do not decrypt the read operation and do not allow the write operation to execute; The encryption process for the write operation specifically includes: Whether the size of the disk space occupied by the file to be processed is less than the block size specified by the block cipher algorithm. If so, use other streaming algorithms to encrypt the file to be processed and end the process; if not, proceed to the next step; If the last two plaintext blocks of the file to be processed are not adjacent, determine whether the current write operation ends with the penultimate plaintext block. If so, process the penultimate write operation and end the process; if not, proceed to the next step; Determine whether it holds that the size of the file to be processed is greater than the block size and the size of the data written in the current write operation is less than the block size. If it holds, process the last write operation and end the process. If it does not hold, proceed to the next step; Determine whether the size of the data written in the current write operation is aligned with the block size. If so, use the block cipher algorithm to encrypt the file to be processed and end the process; if not, use the ciphertext stealing method to encrypt the file to be processed and end the process; The specific steps for processing the last write operation include: Add data of one sector size saved in the Stream Context before the data of the last write operation to make the last two plaintext blocks of the file to be processed adjacent, and use the ciphertext stealing method to encrypt the concatenated data; Retrieve the saved write offset and the size of the write operation data from the Stream Context, modify the write offset and the size of the write operation data in the I / O data request packet to the current write offset and the size of the write operation data, and allow the I / O data request packet to be sent to the file system driver; When the file system driver completes the write operation and returns to the minifilter, restore the return value IoStatus.Information to the size of the write operation data in the I / O data request packet before modification.
Citation Information
Patent Citations
Photo and video cloud encryption storage method
CN109245881A
Secure operation method based on trusted storage of core data file
CN111539042A