File processing method, computer readable storage medium and electronic device
By constructing a file header structure to randomly corrupt and encrypt the AI model, the problem of high computational load in encryption and decryption in existing technologies is solved, achieving efficient protection and deployment on end devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-22
- Publication Date
- 2026-04-07
AI Technical Summary
Existing technologies that fully encrypt AI models result in large encryption and decryption computations, which is not conducive to deployment and implementation on edge devices with limited computing resources.
By constructing a file header structure to randomly corrupt the source file, and then encrypting the random corruption rules and writing them into the source file header, a protected file is formed.
It improves the confidentiality and security of source files while reducing the demand for computing resources, especially improving the speed of deprotection on resource-constrained end devices.
Smart Images

Figure CN115455371B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence (AI) technology, in particular to the field of AI model file processing technology. BACKGROUND
[0002] In the field of AI, after the construction and training of an AI model are completed, the AI model can be deployed and released. If the AI model is not protected, any third party that obtains the model can analyze the model through a model visualization tool (such as netron) or even directly run and use the model. In order to protect one's own AI algorithm model from being used by unauthorized third parties, the prior art encrypts the entire AI model by using an encryption algorithm, then deploys and releases the model, and finally decrypts the model before inference to obtain the original model for inference. However, if the entire AI model is encrypted, the encryption and decryption calculation amount is large when the AI model is large, especially on an end device with limited computing power, which is not conducive to the deployment and landing of the AI model on the end device. SUMMARY
[0003] The present application aims to provide a file processing method, a computer readable storage medium and an electronic device, which can solve the technical problem of large encryption and decryption calculation amount caused by encrypting the entire file when protecting the file in the prior art.
[0004] To achieve the above object and other related objects, the present application provides a file processing method. The method comprises: creating an empty first protection file for a source file; constructing a file header structure associated with the source file based on a pairing area; encrypting the file header structure, and forming a second protection file based on the encrypted file header structure and the first protection file; processing the source file according to the file header structure, and forming a third protection file based on the processed source file and the second protection file.
[0005] In an embodiment of the present application, the file header structure comprises a preset protection magic number, an exchange type, an exchange operation mode, a pairing mode, an exchange area length, an actual pairing number, an odd exchange offset address list, an even exchange offset address list, an odd pairing area list and an even pairing area list.
[0006] In an embodiment of the present application, each pairing area in the odd pairing area list and the even pairing area list is composed of exchange address one and exchange address two.
[0007] In an embodiment of the present application, the method of constructing the file header structure associated with the source file based on the pairing area comprises: generating a preset number of random numbers as an exchange offset address list; and pairing the exchange offset addresses in the exchange offset address list according to a preset rule to divide the exchange offset addresses into a plurality of pairing areas, each of which is composed of two exchange addresses.
[0008] In an embodiment of the present application, the method of encrypting the file header structure and forming a second protection file based on the encrypted file header structure and the first protection file comprises: judging whether the size of the encrypted file header structure is equal to the size of the unencrypted file header structure; if yes, writing the encrypted file header structure into the head of the first protection file; if no, constructing an auxiliary head of a preset size, then writing the auxiliary head into the head of the first protection file and writing the encrypted file header structure into the current tail of the first protection file, wherein the auxiliary head comprises a preset magic number and the size of the encrypted file header structure.
[0009] In an embodiment of the present application, the method of processing the source file according to the file header structure and forming a third protection file based on the processed source file and the second protection file comprises: when the exchange type of the file header structure is odd, setting a temporary pairing area list as the odd pairing area list of the model header structure; when the exchange type of the file header structure is even, setting the temporary pairing area list as the even pairing area list of the model header structure; reading the data of the source file from the head and writing the data of the entire source file into the current tail of the protection file; traversing the temporary pairing area list, the index of which starts from the first element of the temporary pairing area list and ends at the actual pairing number of elements of the model header structure; for each pairing area, generating the protection file based on the exchange addresses of the pairing area and the file header length.
[0010] In an embodiment of the present application, the method of generating the protection file based on the exchange addresses of the pairing area and the file header length for each pairing area comprises: positioning the protection file to the exchange address one of the pairing area plus the file header length, reading the data of the exchange area length of the file header structure into a temporary buffer one; positioning the protection file to the exchange address two of the pairing area plus the file header length, reading the data of the exchange area length of the file header structure into a temporary buffer two; positioning the protection file to the exchange address one of the pairing area plus the file header length, writing the data in the temporary buffer two, the writing data length being the exchange area length of the file header structure; positioning the protection file to the exchange address two of the pairing area plus the file header length, writing the data in the temporary buffer one, the writing data length being the exchange area length of the file header structure.
[0011] In an embodiment of the present application, forming the second protection file based on the encrypted file header structure and the first protection file comprises: writing the encrypted file header structure into the header of the first protection file to form the second protection file.
[0012] In an embodiment of the present application, forming the third protection file based on the processed source file and the second protection file comprises: writing the processed source file into the tail of the second protection file to form the third protection file.
[0013] To achieve the above object and other related objects, the present application further provides a file processing method. The method comprises: receiving a protected file, the protected file comprising first information associated with an encrypted file header structure and second information associated with a processed source file obtained by processing a source file according to the file header structure, wherein the file header structure is constructed based on a pairing area; verifying the first information of the protected file based on a preset file header structure; and in response to the first information of the protected file passing the verification, obtaining the source file based on the second information of the protected file.
[0014] To achieve the above object and other related objects, the present application further provides a computer readable storage medium having computer readable program instructions stored thereon, the program instructions being executed to implement the file processing method.
[0015] To achieve the above object and other related objects, the present application further provides an electronic device comprising: a memory configured to store program instructions; and a processor configured to run the program instructions to implement the file processing method.
[0016] As described above, the file processing method, computer readable storage medium and electronic device of the present application have the following beneficial effects:
[0017] As described above, according to the embodiments of the present application, the scheme of the present application does not encrypt the entire source file (such as an AI model), but randomly destroys the source file through the constructed file header structure and writes the random destruction rule after encryption into the header of the source file. Since the source file is randomly destroyed, the content of each destruction is different for the same source file, and thus the protection file after destruction is also different, thereby maximizing the confidentiality and security of the source file protection. At the same time, since the entire source file is not encrypted, the demand for computing resources is reduced while achieving protection of the source file, especially for the end device deployed in a computing resource limited environment, the speed of source file protection before inference is improved. The method of the present application is suitable for protecting AI models and various application documents, and does not limit the software and hardware environment and scene, and has strong universality. Attached Figure Description
[0018] Figure 1 The diagram shown is a flowchart of a document processing method according to an embodiment of this application.
[0019] Figure 2 The diagram shown is another flowchart of a document processing method according to an embodiment of this application;
[0020] Figure 3 The flowchart shown is a document processing method according to an embodiment of this application, in which the first information of a protected document is verified.
[0021] Figure 4 The flowchart shown is a document processing method according to an embodiment of this application, in which the source file is derived based on the second information of the protected file.
[0022] Figure 5 The flowchart shown is an application example of a file processing method according to an embodiment of this application.
[0023] Figure 6 The diagram shown is a schematic diagram of the principle structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0024] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0025] In existing technologies, the entire AI model is encrypted before deployment and release, and then decrypted before inference to obtain the original model for inference. However, encrypting the entire AI model can be computationally intensive, which is detrimental to the deployment and implementation of AI models on edge devices.
[0026] To address at least the aforementioned issues, this disclosure provides a file processing solution that eliminates the need to encrypt the entire source file. Instead, it constructs a file header structure, randomly corrupts the source file, and encrypts the random corruption rules before writing them into the source file header. This solves the technical problem of high encryption and decryption computational load caused by encrypting the entire file when protecting files in the prior art.
[0027] The following will describe in detail the principles and implementation methods of the document processing method, computer-readable storage medium, and electronic device of the present invention, so that those skilled in the art can understand the document processing method, computer-readable storage medium, and electronic device of the present invention without creative effort.
[0028] Hereinafter, specific embodiments of the present disclosure will be described with reference to the accompanying drawings through exemplary embodiments.
[0029] Figure 1 This is a flowchart illustrating a file processing method according to an embodiment of the present disclosure. Figure 1 As shown, the file processing method includes the following steps S110 to S140.
[0030] In step S110, an empty first protected file is created for the source file. In some embodiments, the source file is an AI model file. In other embodiments, the source file is various application documents.
[0031] In some embodiments, the file extension of the empty protected file is the same as that of the source file. In some embodiments, an empty AI protected model file, such as protected_model.pb, is created, and its file extension must be consistent with that of the AI source file, such as .pb or .onnx.
[0032] In addition, in this embodiment, the file processing method also includes determining the size of the source file, such as determining the size of the AI source file, in preparation for the implementation of subsequent steps S120 to S140.
[0033] In step S120, a file header structure associated with the source file is constructed based on the pairing regions. In some embodiments, the file header structure includes a preset protection magic number, swap type, swap operation mode, pairing mode, swap region length, actual number of pairs, odd swap offset address list, even swap offset address list, odd pairing region list, and even pairing region list. In some embodiments, each pairing region in the odd pairing region list and the even pairing region list consists of swap address one and swap address two, respectively.
[0034] In step S130, the file header structure is encrypted, and a second protected file is formed based on the encrypted file header structure and the first protected file. In some embodiments, the encrypted file header structure is written into the header of the first protected file to form the second protected file.
[0035] In step S140, the source file is processed according to the file header structure, and a third protected file is formed based on the processed source file and the second protected file. In some embodiments, the processed source file is written to the end of the second protected file to form the third protected file.
[0036] The file processing method according to embodiments of this disclosure does not encrypt the entire source file (e.g., an AI model). Instead, it randomly corrupts the source file by constructing a file header structure and encrypts the random corruption rules before writing them into the source file header. Because the source file is randomly corrupted, the corrupted content is different each time, resulting in different protected files, thus maximizing the confidentiality and security of the source file protection. Furthermore, since the entire source file is not encrypted, the requirement for computing resources is reduced while protecting the source file.
[0037] The following section will describe in detail how the file header structure is constructed.
[0038] In some embodiments, the method of constructing a file header structure associated with the source file based on the pairing region includes: generating a set of preset number of random numbers as a list of swap offset addresses; pairing the generated random numbers according to preset rules, dividing the swap offset addresses in the list of swap offset addresses into multiple pairing regions, each pairing region consisting of two swap addresses.
[0039] In this embodiment, the file header structure is composed of a preset protection magic number, swap type (e.g., swap_type), swap operation mode (e.g., swap_op_mode), pairing mode (e.g., swap_match_mode), swap area length (e.g., swap_len), actual pairing number (e.g., match_number), odd swap offset address list, even swap offset address list, odd pairing area list, and even pairing area list.
[0040] Each pairing element in the odd-numbered pairing list and the even-numbered pairing list consists of swap address one and swap address two.
[0041] Specifically, in this embodiment, a set of predetermined random numbers (i.e., an "odd-number swap offset address list" or an "even-number swap offset address list") is generated. Based on the generated set of random numbers (e.g., a1, a2, a3, a4), they are paired according to predetermined rules (e.g., a1 and a4 are paired, a2 and a3 are paired). The final number of paired numbers is the "actual pairing number" (e.g., a1 and a4 are paired, a2 and a3 are paired, so the actual pairing number here is 2). This pairing corresponds to the concept of a "pairing area" in the header structure (multiple "pairing areas" constitute the concept of a "pairing area list"). Each "pairing area" contains two corresponding addresses, called "swap address one" and "swap address two" (e.g., a1 and a4 are paired, so a1 and a4 constitute a pairing area, and swap addresses one and two within it correspond to a1 and a4). Finally, the contents of the source file corresponding to "swap address one" and "swap address two" in the pairing area are swapped. The length of the swapped data (i.e., the "swap area length") is determined according to predetermined rules.
[0042] The "Swap Type" field determines whether the number of random numbers to be generated is odd or even. Different "Swap Types" correspond to different "Swap Operation Modes," with two corresponding "Swap Operation Modes" for both odd and even "Swap Types." Regardless of the "Swap Type" and "Swap Operation Mode," the final "Pairing Mode" rule remains consistent.
[0043] After determining whether the number is odd or even by the "swap type", odd numbers are represented by the "odd swap offset address list" and the "odd pairing area list", while even numbers are represented by the "even swap offset address list" and the "even pairing area list".
[0044] In this embodiment, the "pairing according to preset rules" is determined by the "exchange type", "exchange operation mode" and "pairing mode".
[0045] In this embodiment, the process of constructing the file header structure is as follows:
[0046] (1) Set the protection magic number of the file header structure to the preset magic number.
[0047] (2) Randomly generate a positive integer, perform a modulo operation between the integer and 2, and use the resulting value as the swap type (such as swap_type) of the file header structure, where 0 indicates that the swap type is even and 1 indicates that the swap type is odd.
[0048] (3) Randomly generate a positive integer, perform a modulo operation between the integer and 2, and use the resulting value as the swap operation mode (such as swap_op_mode) of the file header structure, where 0 represents swap operation mode one and 1 represents swap operation mode two.
[0049] (4) Randomly generate a positive integer, perform a modulo operation between the integer and 3, and use the resulting value as the pairing mode (such as swap_match_mode) of the file header structure, where 0 represents pairing mode one, 1 represents pairing mode two, and 2 represents pairing mode three.
[0050] (5) If the swap type (e.g., swap_type) is odd, a set of random integers of a preset odd number is generated as the odd swap offset address list for the file header structure. Otherwise, if the swap type is even, a set of random integers of a preset even number is generated as the even swap offset address list for the file header structure.
[0051] a) The generated random number must be greater than the preset minimum value (e.g., 0) and less than the size of the source file (in bytes).
[0052] b) The elements in the generated list of swapped offset addresses must be distinct from each other.
[0053] c) Arrange the elements in the generated list of swapped offset addresses in ascending order.
[0054] (6) Settings for swap length (e.g., swap_len), actual number of pairs (e.g., match_number), odd-numbered pairing list, and even-numbered pairing list. Specifically:
[0055] 6-1) If the swap type (e.g., swap_type) is odd:
[0056] a) Construct a temporary swap offset address list:
[0057] a-1) If the swap operation mode (e.g., swap_op_mode) is of type swap operation mode one:
[0058] The temporary swap offset address list consists of an odd-numbered swap offset address list.
[0059] a-2) If the swap operation mode (e.g., swap_op_mode) is of type swap operation mode two:
[0060] The temporary swap offset list is constructed by adding one element to the beginning and one to the end of the odd swap offset list. Therefore, the length of the temporary swap offset list is: odd swap offset list + 2. Furthermore, the first element (the first element) of the temporary swap offset list is 0, indicating the start of the source file. The last element (the last element) of the temporary swap offset list is: source file size (in bytes) - 1.
[0061] b) Subtract each pair of directly adjacent swap offset addresses in the temporary swap offset address list in sequence to obtain a set of adjacent differences. The length of this set of adjacent differences is: the length of the temporary swap offset address list - 1.
[0062] c) Use the minimum value of the obtained adjacent differences as the length of the swap area in the file header structure (e.g., swap_len).
[0063] d) Divide the length of the resulting adjacent difference by 2 and round down to get the actual number of pairs in the file header structure (e.g., match_number).
[0064] e) The odd-numbered pairing list is set according to the following rules:
[0065] e-1) If the pairing mode (e.g., swap_match_mode) is pairing mode one:
[0066] Iterate through the list of odd-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair:
[0067] Set the swap address of the paired area element to the value of the "traversal index (e.g., index)" element in the temporary swap offset address list.
[0068] Set the swap address of the paired area element to the value of the element in the temporary swap offset address list that is "(index of the last element in the temporary swap offset address list)-1-traversal index".
[0069] e-2) If the pairing mode (e.g., swap_match_mode) is pairing mode two:
[0070] Iterate through the list of odd-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair:
[0071] Set the swap address of the paired area element to the value of the element at the second traversal index (e.g., index) in the temporary swap offset address list.
[0072] Set the swap address of the paired area element to the value of the "2nd traversal index (e.g., index) + 1" element in the temporary swap offset address list.
[0073] e-3) If the pairing mode (e.g., swap_match_mode) is pairing mode three:
[0074] The initial value of the random selection list is set to: a temporary swap offset address list after removing the last element. Therefore, the initial length of this random selection list is: the length of the temporary swap offset address list - 1.
[0075] Iterate through the list of odd-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair:
[0076] Set the swap address of the paired elements to the value of the first element in the list randomly selected.
[0077] Generate a random positive integer. Take the modulo operation between this integer and the length of the random selection list, and use the result as the random selection index. If the random selection index is 0 (i.e., the first element), increment the random selection index by 1.
[0078] The second swap address for the paired elements is set to a value at a randomly selected index position from the list.
[0079] Update the random selection list and its length: Take all elements from the current random selection list except the first element and the element at the random selection index, and construct a new random selection list in order. Use this new random selection list as the new value of the random selection list. Simultaneously, set the length of the new random selection list to "the length of the random selection list - 2".
[0080] 6-2) If the swap type (e.g., swap_type) is even:
[0081] a) Construct a temporary swap offset address list:
[0082] a-1) If the swap operation mode (e.g., swap_op_mode) is of type swap operation mode one:
[0083] The temporary swap offset list is formed by adding one element to the beginning of the even-numbered swap offset list. Therefore, the length of the temporary swap offset list is: even-numbered swap offset list + 1. And the first element (the first element) of the temporary swap offset list is 0, indicating the starting position of the source file.
[0084] a-2) If the swap operation mode (e.g., swap_op_mode) is of type swap operation mode two:
[0085] The temporary swap offset list is formed by adding an element to the end of the even-numbered swap offset list. Therefore, the length of the temporary swap offset list is: even-numbered swap offset list + 1. And the last element of the temporary swap offset list is: source file size (in bytes) - 1.
[0086] b) Subtract each pair of directly adjacent swap offset addresses in the temporary swap offset address list in sequence to obtain a set of adjacent differences. The length of this set of adjacent differences is: the length of the temporary swap offset address list - 1.
[0087] c) Use the minimum value of the obtained adjacent differences as the length of the swap area in the file header structure (e.g., swap_len).
[0088] d) Divide the length of the resulting adjacent difference by 2 and round down to get the actual number of pairs in the file header structure (e.g., match_number).
[0089] e) The even-numbered pairing list is set according to the following rules:
[0090] e-1) If the pairing mode (e.g., swap_match_mode) is pairing mode one:
[0091] Iterate through the list of even-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair: set the swap address of the pair element to the value of the element at the "traversal index (e.g., index)" in the temporary swap offset address list.
[0092] Set the swap address of the paired area element to the value of the element in the temporary swap offset address list that is "(index of the last element in the temporary swap offset address list)-1-traversal index".
[0093] e-2) If the pairing mode (e.g., swap_match_mode) is pairing mode two:
[0094] Iterate through the list of even-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair:
[0095] Set the swap address of the paired area element to the value of the element at the second traversal index (e.g., index) in the temporary swap offset address list.
[0096] Set the swap address of the paired area element to the value of the "2nd traversal index (e.g., index) + 1" element in the temporary swap offset address list.
[0097] e-3) If the pairing mode (e.g., swap_match_mode) is pairing mode three:
[0098] The initial value of the random selection list is set to: a temporary swap offset address list after removing the last element. Therefore, the initial length of this random selection list is: the length of the temporary swap offset address list - 1.
[0099] Iterate through the list of even-numbered pairs, starting from the first element of the list (index = 0) and continuing until the actual number of pairs (match_number - 1). For each pair:
[0100] Set the swap address of the paired elements to the value of the first element in the list randomly selected.
[0101] Generate a random positive integer. Take the modulo operation between this integer and the length of the random selection list, and use the result as the random selection index. If the random selection index is 0 (i.e., the first element), increment the random selection index by 1.
[0102] The second swap address for the paired elements is set to a value at a randomly selected index position from the list.
[0103] Update the random selection list and its length: Take all elements from the current random selection list except the first element and the element at the random selection index, and construct a new random selection list in order. Use this new random selection list as the new value of the random selection list. Simultaneously, set the length of the new random selection list to "the length of the random selection list - 2".
[0104] In some embodiments, encrypting the file header structure and forming a second protected file based on the encrypted file header structure and the first protected file includes: encrypting the constructed file header structure using an encryption algorithm; determining whether the size of the encrypted file header structure is equal to the size of the file header structure before encryption; if so, writing the encrypted file header structure into the header of the first protected file; if not, constructing an auxiliary header of a preset size, then writing the auxiliary header into the header of the first protected file, and writing the encrypted file header structure into the current tail of the first protected file, wherein the auxiliary header includes a preset magic number and the size of the encrypted file header structure.
[0105] For example, first, the constructed model header structure of a preset size is encrypted using a preset symmetric encryption algorithm and key. Then, it is determined whether the size of the encrypted model header structure is equal to the size of the original model header structure.
[0106] If the sizes are equal, the encrypted model header structure is written into the header of the AI-protected model file (e.g., protected_model.pb). The size of the encrypted model header structure is used as the model header length (e.g., protected_model_header_len).
[0107] If the sizes are not equal, construct an auxiliary header of a preset size. This auxiliary header includes two pieces of information: the preset magic number and the size of the encrypted model header structure. Then, write the auxiliary header into the header of the AI-protected model file (e.g., protected_model.pb) and write the encrypted model header structure into the current footer of the AI-protected model file (e.g., protected_model.pb).
[0108] Use "the size of the auxiliary header of the preset size + the size of the encrypted model header structure" as the model header length (e.g., protected_model_header_len).
[0109] In some embodiments, processing the source file according to the file header structure and forming a third protection file based on the processed source file and the second protection file includes: setting a temporary pairing list to the odd-numbered pairing list of the model header structure when the swap type of the file header structure is odd, and setting a temporary pairing list to the even-numbered pairing list of the model header structure when the swap type of the file header structure is even; reading the data of the source file from the beginning and writing the entire data of the source file to the current end of the protection file; traversing the temporary pairing list, with the traversal index starting from the first element of the temporary pairing list and continuing until the actual number of paired elements of the model header structure; and for each pairing, generating a protection file based on the swap address of the pairing area and the file header length.
[0110] Specifically, generating a protection file for each paired region based on the swap address and file header length of the paired region includes:
[0111] 1) Locate the protected file at the swap address of the paired area, add the file header length, and read the data of the swap area length of the file header structure into temporary buffer 1;
[0112] 2) Locate the protected file at the swap address 2 of the paired area, add the file header length, and read the data of the swap area length of the file header structure into temporary buffer 2;
[0113] 3) Locate the protected file at the swap address one of the pairing area plus the file header length, and write the data in temporary buffer two. The length of the written data is the swap area length of the file header structure.
[0114] 4) Locate the protected file at the swap address 2 of the pairing area plus the file header length, and write the data in temporary buffer 1. The length of the written data is the swap area length of the file header structure.
[0115] For example, the source model is read, and an AI-protected model file is constructed based on the pairing region information of the model's header structure. The specific process is as follows:
[0116] (1) If the swap type (e.g., swap_type) of the model header structure is odd: Set the temporary pairing list to the odd-numbered pairing list of the model header structure. Otherwise, if the swap type (e.g., swap_type) of the model header structure is even: Set the temporary pairing list to the even-numbered pairing list of the model header structure.
[0117] (2) Read the data from the source model file from the beginning and write the data of the entire source model file to the current end of the AI protected model file (such as protected_model.pb).
[0118] (3) Traverse the temporary pairing list, starting from the first element of the temporary pairing list (index=0) and continuing until the actual number of pairs (match_number-1) elements in the model head structure. For each pairing:
[0119] a) Locate the AI protected model file to "the swap address of the paired area element plus the model header length", and read the data of the size of "the swap area length of the model header structure" into temporary buffer one.
[0120] b) Locate the AI protected model file to "the swap address of the paired area element plus the model header length", and read the data of the size of "the swap area length of the model header structure" into temporary buffer two.
[0121] c) Locate the AI protected model file to "the swap address of the paired area element plus the model header length", and then write the data in temporary buffer two. The length of the written data is "the swap area length of the model header structure".
[0122] d) Locate the AI-protected model file to "the swap address of the paired area element plus the model header length", and then write the data in temporary buffer one. The length of the written data is "the swap area length of the model header structure".
[0123] In some embodiments, the file processing method may further include obtaining the source file, which includes an artificial intelligence source model file.
[0124] In some embodiments, after the third protection file is generated, the file processing method may further include performing publishing and deployment based on the third protection file.
[0125] According to embodiments of this disclosure, the source file is randomly corrupted by constructing a file header structure, and the random corruption rules are encrypted and written into the source file header. Because the source file is randomly corrupted, the corrupted content is different each time for the same source file, resulting in different protected files after corruption, thus maximizing the confidentiality and security of the source file protection. Simultaneously, since the entire source file is not encrypted, the demand for computing resources is reduced while protecting the source file.
[0126] Figure 2 This is another flowchart illustrating a file processing method according to an embodiment of the present disclosure. Figure 2 As shown, the file processing method includes the following steps S210 to S230.
[0127] In step S210, a protected file is received, the protected file including first information associated with an encrypted file header structure and second information associated with a processed source file obtained by processing the source file according to the file header structure, wherein the file header structure is constructed based on a pairing region.
[0128] In step S220, the first information of the protected file is verified based on a preset file header structure.
[0129] like Figure 3 As shown, verifying the first information of the protected file based on the preset file header structure includes the following steps S221 to S223.
[0130] In step S221, the encrypted file header structure is derived from the header of the protected file.
[0131] In step S222, the encrypted file header structure is decrypted using a preset symmetric encryption algorithm and key.
[0132] In step S223, the decrypted file header structure is verified based on the preset file header structure.
[0133] Specifically, this embodiment verifies the header of the protected file in the following way:
[0134] Read the auxiliary header of a preset size from the header of the protected file, and determine whether the magic number of the auxiliary header is the same as the preset magic number:
[0135] If they are the same, after locating the protected file to the auxiliary header, data of a specified size is read into a temporary buffer according to the "size of the encrypted file header structure" in the auxiliary header, which serves as the encrypted file header structure. The "preset size of the auxiliary header" plus the "size of the encrypted file header structure" is used as the length of the temporary file header (e.g., protected_model_header_len).
[0136] If they are different, locate the header of the protected file, read the file header structure of the preset size into a temporary buffer, and use it as the encrypted file header structure. Use the preset size of the file header structure as the length of the temporary file header (e.g., protected_model_header_len).
[0137] Step S230: In response to the first information of the protected file being verified, the source file is derived based on the second information of the protected file.
[0138] In some embodiments, such as Figure 4 As shown, deriving the source file based on the second information of the protected file includes the following steps S231 and S232.
[0139] In step S231, the processed source file is derived from the end of the protected file.
[0140] In step S232, the source file is decoded from the processed source file according to the file header structure, and the source file is stored in the target buffer.
[0141] Furthermore, in some embodiments, deriving the source file based on the second information of the protected file includes: decrypting the encrypted file header structure in the temporary buffer using a preset symmetric encryption algorithm and key to obtain the decrypted file header structure. It is then determined whether the protection magic number in the decrypted file header structure is the same as the preset protection magic number: if they are the same, a target file buffer is pre-allocated; otherwise, an invalid file is indicated, and the process exits.
[0142] Pre-allocate a target file buffer, the size of which is at least: the size of the protected file minus the length of the temporary file header. Initialize the pre-allocated target file buffer (e.g., initialize all buffers to 0x00).
[0143] In this embodiment, the specific process of decoding the source file from the protected file and storing the source file in the target buffer is as follows:
[0144] (1) If the swap type (e.g., swap_type) of the file header structure is odd: Set the temporary pair list to the odd-numbered pair list of the file header structure. Otherwise, if the swap type (e.g., swap_type) of the file header structure is even: Set the temporary pair list to the even-numbered pair list of the file header structure.
[0145] (2) Position the protected model file to the length of the temporary header (e.g., protected_model_header_len), and then read the data of size "size of protected file - length of temporary header" into the pre-allocated target file buffer.
[0146] (3) Traverse the temporary pairing list, starting from the first element of the temporary pairing list (index = 0) and continuing until the actual number of pairs (match_number - 1) elements in the file header structure. For each pairing:
[0147] a) Position the target file buffer to the swap address of the paired area element, and read data of size "swapping length of file header structure" into temporary buffer one.
[0148] b) Locate the target file buffer at the swap address two of the paired area elements, and read data of the size of "swapping area length of file header structure" into temporary buffer two.
[0149] c) Position the target file buffer to the swap address one of the paired area elements, and then write the data in temporary buffer two. The length of the written data is "the swap area length of the file header structure".
[0150] d) Position the target file buffer to the swap address two of the paired area element, and then write the data in temporary buffer one. The length of the written data is "the swap area length of the file header structure".
[0151] Figure 5 The following example illustrates the implementation process of the file processing method described in this embodiment, using AI source files as an example.
[0152] like Figure 5As shown, when protecting the AI source model file, the process involves obtaining the AI source model file, creating an empty AI protected model file, constructing a model header structure based on the pairing region and the file header structure associated with the source file, encrypting the constructed model header structure, writing it into the header of the AI protected model file, reading the source model, constructing the AI protected model file based on the information in the model header structure, and publishing the processed AI protected model file for actual deployment. When the AI source model file is to be used, the protected model header is verified, the original model is decoded from the protected model file, and stored in the target model buffer. In this embodiment, the entire AI model is not encrypted during the AI model protection process. Instead, the AI model is randomly corrupted, and the random corruption rules are encrypted and written into the AI model header. Because the AI model is randomly corrupted, the content corrupted is different each time for the same AI model, resulting in a different AI protected model after corruption, thereby maximizing the confidentiality and security of AI model protection. Simultaneously, since the entire AI model is not encrypted, the demand for computing resources is reduced while protecting the AI model, especially for end devices with limited computing resources, improving the speed of AI model deprotection before inference. The method in this embodiment is applicable to protecting any AI model, without restrictions on software and hardware environments and scenarios, and has strong versatility.
[0153] Figure 6 This is a block diagram illustrating an electronic device according to an embodiment of the present disclosure. (As shown) Figure 6 As shown, this embodiment provides an electronic device 101, which includes a processor 1001 and a memory 1002. The memory 1002 is used to store computer programs. The processor 1001 is used to execute the computer programs stored in the memory 1002, so that the electronic device 101 performs the steps of the file processing method as described in Embodiment 1. Since the specific implementation process of each step of the file processing method has been described in detail in Embodiment 1, it will not be repeated here.
[0154] Processor 1001 is a CPU (Central Processing Unit). Memory 1002 is connected to processor 1001 via a system bus and communicates with it. Memory 1002 stores computer programs, and processor 1001 runs the computer programs to execute the file processing method described above. Memory 1002 may include random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0155] Furthermore, this embodiment also provides a computer-readable storage medium storing a computer program thereon, which, when executed by the processor 1001, implements the aforementioned file processing method. The file processing method has already been described in detail above and will not be repeated here.
[0156] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented using computer program-related hardware. The aforementioned computer program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0157] In summary, this application does not encrypt the entire source file (e.g., AI model file). Instead, it randomly corrupts the source file by constructing a file header structure, and then encrypts the random corruption rules and writes them into the source file header. Because the source file is randomly corrupted, the corrupted content is different each time, resulting in different protected files. This maximizes the confidentiality and security of the source file protection. Furthermore, since the entire source file is not encrypted, the demand for computing resources is reduced while protecting the source file, especially for devices with limited computing resources, thus improving the speed of deprotection before inference. The method of this application is applicable to protecting AI model files and various application documents, without limitations on software and hardware environments or scenarios, and has strong versatility. Therefore, this invention effectively overcomes the various shortcomings of existing technologies and has high industrial applicability.
[0158] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A file processing method, characterized in that, include: Create an empty first protected file for the source file; Construct a file header structure associated with the source file based on the pairing region; The file header structure is encrypted, and a second protected file is formed based on the encrypted file header structure and the first protected file; as well as The source file is processed according to the file header structure, and a third protected file is formed based on the processed source file and the second protected file. The construction of the file header structure associated with the source file based on the pairing region includes: generating a set of preset number of random numbers as a list of swapped offset addresses; Based on the generated random numbers, the exchange offset addresses in the exchange offset address list are paired according to preset rules, and the exchange offset addresses are divided into multiple pairing areas, each pairing area consisting of two exchange addresses.
2. The file processing method according to claim 1, characterized in that, The file header structure includes a preset protected magic number, swap type, swap operation mode, pairing mode, swap area length, actual number of pairs, odd swap offset address list, even swap offset address list, odd pairing area list, and even pairing area list.
3. The file processing method according to claim 2, characterized in that, Each pairing region in the odd-numbered pairing region list and the even-numbered pairing region list consists of exchange address one and exchange address two, respectively.
4. The file processing method according to claim 1, characterized in that, Encrypting the file header structure and forming a second protected file based on the encrypted file header structure and the first protected file includes: Determine whether the size of the encrypted file header structure is equal to the size of the unencrypted file header structure; If so, the encrypted file header structure is written into the header of the first protected file; If not, an auxiliary header of a preset size is constructed, and then the auxiliary header is written into the header of the first protected file, and the encrypted file header structure is written into the current tail of the first protected file, wherein the auxiliary header includes a preset magic number and the size of the encrypted file header structure.
5. The document processing method according to claim 3, characterized in that, Processing the source file according to the file header structure and forming a third protected file based on the processed source file and the second protected file includes: When the swap type of the file header structure is odd, the temporary pairing list is set to the odd-numbered pairing list of the model header structure; when the swap type of the file header structure is even, the temporary pairing list is set to the even-numbered pairing list of the model header structure. Read the data from the source file from the beginning and write the entire data from the source file to the current end of the protected file; Traverse the list of temporary pairing regions, starting from the first element of the list and continuing up to the actual number of paired elements in the model header structure. For each pairing region, generate a protection file based on the pairing region's swap address and the file header length.
6. The document processing method according to claim 5, characterized in that, The process of generating a protection file for each paired region based on the swap address and file header length of the paired region includes: The protected file is located at the swap address of the paired area, and the file header length is added. The data of the swap area length of the file header structure is then read into the temporary buffer. The protected file is located at the swap address of the paired area plus the file header length, and the data of the swap area length of the file header structure is read into the temporary buffer 2. The protected file is located at the swap address of the pairing area plus the file header length, and the data in the temporary buffer is written. The length of the written data is the swap area length of the file header structure. The protected file is located at the swap address two of the paired area, plus the file header length. The data in temporary buffer one is written, and the length of the written data is the swap area length of the file header structure.
7. The document processing method according to claim 1, characterized in that, Forming a second protected file based on the encrypted file header structure and the first protected file includes: writing the encrypted file header structure into the header of the first protected file to form the second protected file.
8. The document processing method according to claim 1, characterized in that, Forming a third protected file based on the processed source file and the second protected file includes: writing the processed source file to the end of the second protected file to form the third protected file.
9. A file processing method, characterized in that, include: A protected file is received, the protected file including first information associated with an encrypted file header structure and second information associated with a processed source file obtained by processing the source file according to the file header structure, wherein the file header structure is constructed based on a pairing region, which includes generating a set of preset number of random numbers as a list of swap offset addresses, pairing the generated random numbers according to preset rules, dividing the swap offset addresses in the list of swap offset addresses into multiple pairing regions, each pairing region consisting of two swap addresses; The first information of the protected file is verified based on the preset file header structure; as well as In response to the first information of the protected file being verified, the source file is derived based on the second information of the protected file.
10. A computer-readable storage medium storing computer-readable program instructions thereon, characterized in that, When the program instructions are executed, the file processing method according to any one of claims 1 to 8 or the file processing method according to claim 9 is used.
11. An electronic device, characterized in that, include: The memory is configured to store program instructions; as well as The processor is configured to execute the program instructions to implement the file processing method according to any one of claims 1 to 8 or the file processing method according to any one of claims 9.
Citation Information
Patent Citations
File processing method and file processing device
CN104732159A
Method and equipment for generating encrypted file
CN112241538A