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 cost in encryption and decryption in existing technologies is solved, thereby improving the security of the model and the deployment efficiency on end devices.

CN115455373BActive Publication Date: 2026-04-07FUZHOU ROCKCHIP SEMICON
View PDF 2 Cites 0 Cited by

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

Technical Problem

The encryption and decryption computations required by existing technologies for encrypting the entire AI model are large, which affects the deployment and implementation of the AI ​​model on end devices.

Method used

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, the encryption of the entire file is avoided.

Benefits of technology

It improves the confidentiality and security of source files while reducing the demand for computing resources, especially improving the speed of inference-before-deciphering protection on computing-limited end devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115455373B_ABST
    Figure CN115455373B_ABST
Patent Text Reader

Abstract

The application provides a file processing method, a computer readable storage medium and an electronic device. 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 group type; 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. The application does not encrypt the entire source file, thereby reducing the demand for computing resources while protecting the source file. In particular, for an end device deployed in a computing resource-limited environment, the speed of source file protection before inference is improved. The method of the application is suitable for protecting AI models and various application documents, and does not limit the software and hardware environment and scene, and is highly versatile.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence (AI), in particular to the technical field of AI model file processing. BACKGROUND

[0002] In the AI field, 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 the like, 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, when the AI model is large, the encryption and decryption calculation amount is large, especially for an end device, the calculation capability is limited, 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 be used to 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 group type; 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 is composed of a preset protection magic number, a grouping mode, an operation point offset address list, an actual group number, a group length type and an operation group list.

[0006] In an embodiment of the present application, each operation group in the operation group list is composed of a group length, a group offset address list, a head-tail node mode, a head node offset address of the group, a tail node offset address of the group, a group type, a group type one head structure and a group type two head structure.

[0007] In an embodiment of the present application, the constructing the file header structure associated with the source file based on the group type comprises: generating a preset number of random numbers; grouping the source file according to a preset rule based on the generated random numbers, and randomly determining a group type for each group of source files; and constructing a corresponding file header structure for each group according to the group type of each group.

[0008] In an embodiment of the present application, the group type is a header structure composed of an actual operation area number and an operation area list, each operation area in the operation area list comprising an offset address, a target offset address and an operation length; and the constructing a corresponding file header structure for each group according to the group type of each group comprises: randomly generating a first group of random numbers and a second group of random numbers, wherein the first group of random numbers corresponds to the offset addresses of the operation areas in the source file, and the second group of random numbers corresponds to the target offset addresses of the operation areas in the source file; and inserting a third group of random numbers as the operation length at the offset addresses of each operation area, wherein the starting positions of the third group of random numbers are determined by the target offset addresses of the operation areas.

[0009] In an embodiment of the present application, the group type is a two-header structure composed of a swap type, a swap operation mode, a pairing mode, a swap area length, an actual pairing number, an odd swap offset address list, an even swap offset address list, an odd pairing area list and an even pairing area list; and the constructing the file header structure comprises: generating a preset number of random numbers as the swap offset address list; and pairing the generated random numbers according to a preset rule, and dividing the swap offset address list into a plurality of pairing areas, each pairing area being composed of two swap addresses.

[0010] In an embodiment of the present application, the encrypting the file header structure and forming a second protection file based on the encrypted file header structure and the first protection file comprises: determining whether the size of the encrypted file header structure is equal to the size of the file header structure before encryption, if yes, writing the encrypted file header structure into the header of the first protection file; and if no, constructing an auxiliary header of a preset size, then writing the auxiliary header into the header of the first protection file, and writing the encrypted file header structure into the current tail of the first protection file, wherein the auxiliary header comprises a preset magic number and the size of the encrypted file header structure.

[0011] In an embodiment of the present application, the forming a 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 a third protection file based on the processed source file and the second protection file comprises: writing the processed source file to 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 group type; 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 stored thereon computer readable program instructions, which, when executed, 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 execute the program instructions to implement the file processing method.

[0016] As described above, according to embodiments of the present disclosure, the scheme of the present application does not encrypt the entire source file (such as an AI model), but rather randomly destroys the source file through a constructed file header structure and writes the random destruction rule after encryption into the source file header. Since the source file is randomly destroyed, the content of each destruction is different for the same source file, and thus the protected 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 end devices deployed in computing resource-limited environments, which improves the speed of source file deprotection before inference. 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. BRIEF DESCRIPTION OF DRAWINGS

[0017] Figure 1 a flowchart showing a file processing method according to an embodiment of the present application;

[0018] Figure 2 another flowchart showing a file processing method according to an embodiment of the present application;

[0019] Figure 3 A flowchart showing a verification process of first information of a protected file in a file processing method according to an embodiment of the present application;

[0020] Figure 4 A flowchart showing a process of deriving a source file based on second information of a protected file in a file processing method according to an embodiment of the present application;

[0021] Figure 5 A flowchart showing an application example of a file processing method according to an embodiment of the present application;

[0022] Figure 6 A schematic diagram showing a principle structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0023] The present application will be described in detail below with specific reference to particular embodiments. The skilled person will readily appreciate from the disclosure herein other advantages and purposes of the present application. The present application can be implemented or applied in other different embodiments, and the details in the present specification can be modified or changed based on different views and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0024] In the prior art, the entire AI model is encrypted, then deployed and published, and finally decrypted before model inference to obtain the original model for inference. However, if the entire AI model is encrypted, the encryption and decryption calculation amount can be large, which is not conducive to the deployment and landing of the AI model on the end device.

[0025] To solve at least the above problems, the present disclosure provides a file processing scheme, which does not need to encrypt the entire source file, but constructs a file header structure associated with the source file based on a group type, randomly destroys the source file, and writes the random destruction rule into the source file header after encryption, thereby solving the technical problem of large encryption and decryption calculation amount caused by encrypting the entire file in the prior art when protecting the file.

[0026] Hereinafter, specific embodiments of the present disclosure will be described by way of exemplary embodiments with reference to the accompanying drawings.

[0027] Figure 1 is a flowchart showing a file processing method according to an embodiment of the present disclosure. As shown in Figure 1 , the file processing method includes the following steps S110 to S140.

[0028] In step S110, an empty first protected file is created for a source file. In some embodiments, the source file is an AI model file. In other embodiments, the source file is various application documents.

[0029] In some embodiments, the suffix name of the empty protection file is the same as that of the source file. In some embodiments, an empty AI protection model file is created, such as protected_model.pb, and the suffix name needs to be consistent with that of the AI source file, such as.pb or.onnx.

[0030] In addition, in some embodiments, the file processing method can further include determining the size of the source file, preparing for the implementation of subsequent steps S120 to S140.

[0031] In step S120, a file header structure associated with the source file is constructed based on the group type. In some embodiments, the file header structure is composed of a preset protection magic number, a grouping mode, a list of operation point offset addresses, an actual group number, a group length type, and a list of operation groups. In some embodiments, each operation group in the list of operation groups is composed of a group length, a list of group offset addresses, a head-tail node mode, a head node offset address of the group, a tail node offset address of the group, a group type, a group type one head structure, and a group type two head structure.

[0032] In step S130, the file header structure is encrypted, and a second protection file is formed based on the encrypted file header structure and the first protection file. In some embodiments, the encrypted file header structure is written to the head of the first protection file to form the second protection file.

[0033] In step S140, the source file is processed according to the file header structure, and a third protection file is formed based on the processed source file and the second protection file. In some embodiments, the processed source file is written to the tail of the second protection file to form the third protection file.

[0034] The file processing method according to the embodiments of the present disclosure 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 to the head of the source file. Since the source file is randomly destroyed, the content of each destruction is different for the same source file, so the protection file after destruction is also different, which maximizes 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.

[0035] Hereinafter, the way of constructing the file header structure will be described in detail.

[0036] In some embodiments, constructing the file header structure associated with the source file based on the group type comprises: generating a preset number of random numbers; grouping the source file according to a preset rule according to the generated random numbers, and randomly determining a group type for each group of source files; and constructing a corresponding file header structure for each group according to the group type of each group.

[0037] In this embodiment, the file header structure is composed of a preset protection magic number, a grouping mode (such as group_divide_mode), an operation point offset address list (such as op_offset), an actual group number (such as group_number), a group length type (such as group_len_type), and an operation group list.

[0038] Each operation group element in the operation group list is composed of a group length (such as group_len), a group offset address list (such as group_offset), a head-tail node mode (such as group_head_tail_mode), a head node offset address of the group (such as group_head_offset), a tail node offset address of the group (such as group_tail_offset), a group type (such as group_type), a group type one head structure, and a group type two head structure.

[0039] The group type one head structure is composed of an actual operation area number (such as gap_num) and an operation area list. Each operation area in the operation area list is composed of an offset address, a target offset address, and an operation length. The group type two head structure is composed of a swap type (such as swap_type), a swap operation mode (such as swap_op_mode), a matching mode (such as swap_match_mode), a swap area length (such as swap_len), an actual matching number (such as match_number), an odd swap offset address list, an even swap offset address list, an odd matching area list, and an even matching area list.

[0040] Each matching area element in the odd matching area list and the even matching area list is composed of a swap address one and a swap address two.

[0041] Specifically, in this embodiment, a preset number of random numbers (i.e., an "operation point offset address list") are generated, the source file is grouped according to the generated random numbers according to a preset rule, the source file is segmented, each segment corresponds to a group, and then different groups are applied different ways to construct the file header structure according to the randomly determined group type (i.e., the "group type" of the operation group).

[0042] Each group is represented by "operation group", the actual number of groups is represented by "actual group number", and all groups constitute the concept of "operation group list". The "group type" in the "operation group" determines whether to apply the basic idea of constructing the file header structure based on the operation area list or the basic idea of constructing the file header structure based on the paired area. The "group type one head structure" is the information required by the basic idea of constructing the file header structure based on the operation area list, and the "group type two head structure" is the information required by the basic idea of constructing the file header structure based on the paired area.

[0043] The boundary of each operation group is determined by the "head node offset address of the group" and the "tail node offset address of the group". There are two grouping methods, corresponding to "grouping mode", and different grouping modes have different configuration rules for groups (i.e. "operation groups"). Grouping mode one uses the generated random number (i.e. "operation point offset address list") as the boundary of the group, and generates a group of random numbers (i.e. "group offset address list") inside each group. The number of generated random numbers is determined by the "group length" of the operation group. Grouping mode two divides the operation points into different groups according to the generated random number (i.e. "operation point offset address list") as the basis according to the preset rule. "Group length type" and "head-tail node mode" are only used in grouping mode two to assist in dividing groups.

[0044] Different grouping methods use different methods to determine the boundary of each operation group (i.e. "head node offset address of the group" and "tail node offset address of the group"). In grouping mode two, the three "head-tail node modes" are used to determine.

[0045] In this embodiment, when the group type is a one-head structure composed of the actual number of operation areas and the operation area list, each operation area in the operation area list includes an offset address, a target offset address, and an operation length; and constructing the corresponding file header structure of each group according to the group type of each group includes: randomly generating a first group of random numbers and a second group of random numbers, wherein the first group of random numbers corresponds to the offset address of the operation area in the source file, and the second group of random numbers corresponds to the target offset address of the operation area in the source file; and inserting a third group of random numbers as the operation length after the offset address of each operation area, wherein the starting position of the third group of random numbers is determined by the target offset address of the operation area.

[0046] In the embodiment, when the group type is a two-head structure composed of the exchange type, the exchange operation mode, the pairing mode, the exchange area length, the actual pairing number, the odd exchange offset address list, the even exchange offset address list, the odd pairing area list, and the even pairing area list; the method for constructing the file head structure comprises: generating a preset number of random numbers as the exchange offset address list; and pairing the generated random numbers according to a preset rule, and dividing the exchange offset addresses in the exchange offset address list into a plurality of pairing areas, each of which is composed of two exchange addresses.

[0047] Specifically, in the embodiment, the construction process of the file head structure is as follows:

[0048] (1) setting the protection magic number of the file head structure as a preset magic number.

[0049] (2) randomly generating a positive integer, and taking the modulus of the integer with 2 to obtain a value as the grouping mode (such as group_divide_mode) of the file head structure, wherein for example, 0 represents grouping mode one, and 1 represents grouping mode two.

[0050] (3) if the grouping mode (such as group_divide_mode) is mode one:

[0051] (3-1) setting the actual group number (such as group_number) of the file head structure as a preset group number.

[0052] (3-2) generating a group of random integers with a number of “actual group number-1” as the operation point offset address list (such as op_offset) of the file head structure, that is, the length of the operation point offset address list is “actual group number-1”, and the following requirements are required:

[0053] a) the generated random number is required to be greater than a preset minimum value (such as 0) and less than the size of the source file (in bytes).

[0054] b) the elements in the above operation point offset address list generated must be different from each other.

[0055] c) the elements in the above operation point offset address list generated are arranged in ascending order.

[0056] (3-3) traversing the operation group list of the file head structure, and the traversal index (such as index) starts from the first element of the operation group list (index=0) until the actual group number (such as group_number) of elements. For each operation group:

[0057] (3-3-1) Set the "head node offset address of the group (e.g. group_head_offset)" and "tail node offset address of the group (e.g. group_tail_offset)" of the operation group.

[0058] a) If it is the first operation group:

[0059] Set the head node offset address of the group (e.g. group_head_offset) as 0;

[0060] Set the tail node offset address of the group (e.g. group_tail_offset) as the value of the "index-th" element of the list of operation point offset addresses.

[0061] b) If it is the last operation group:

[0062] Set the head node offset address of the group (e.g. group_head_offset) as the value of the "(index-1)-th" element of the list of operation point offset addresses;

[0063] Set the tail node offset address of the group (e.g. group_tail_offset) as the size of the source file in bytes;

[0064] c) For other operation groups:

[0065] Set the head node offset address of the group (e.g. group_head_offset) as the value of the "(index-1)-th" element of the list of operation point offset addresses;

[0066] Set the tail node offset address of the group (e.g. group_tail_offset) as the value of the "index-th" element of the list of operation point offset addresses;

[0067] (3-3-2) Set the group length (e.g. group_len) of the operation group:

[0068] Randomly generate an integer, requiring that the generated random number is not less than the preset minimum group length (e.g. 3) and not greater than the preset maximum group length. The obtained random integer that meets the requirements is taken as the group length (e.g. group_len) of the operation group.

[0069] (3-3-3) Set the group offset address list (e.g. group_offset) of the operation group:

[0070] Generate a set of random integers as the group offset address list of the operation group (such as group_offset), that is, the length of the group offset address list of the operation group is the group length of the current operation group, and require:

[0071] a) The generated random number is required to be greater than the head node offset address of the group and less than the tail node offset address of the group.

[0072] b) The elements in the generated group offset address list must be different from each other.

[0073] c) The elements in the generated group offset address list are arranged in ascending order.

[0074] (3-3-4) Set the group type of the operation group (such as group_type):

[0075] Randomly generate a positive integer, take the modulus of the integer with 2, and get the value as the group type of the operation group, where 0 represents group type one and 1 represents group type two.

[0076] (3-3-5) If the group type of the operation group is group type one, set the group type one header structure of the operation group according to the rules in (4) as follows:

[0077] (3-3-6) If the group type of the operation group is group type two, set the group type two header structure of the operation group according to the rules in (5) as follows:

[0078] If the group mode (such as group_divide_mode) is mode two:

[0079] (3-1) Generate a set of random integers as the operation point offset address list of the file header structure (such as op_offset) with a preset number, and require:

[0080] a) The generated random number is required to be greater than the preset minimum value (such as 0) and less than the size of the source file in bytes.

[0081] b) The elements in the generated operation point offset address list must be different from each other.

[0082] c) The elements in the generated operation point offset address list are arranged in ascending order.

[0083] (3-2) Set the group length type of the file header structure (such as group_len_type):

[0084] A positive integer is randomly generated, and the integer is subjected to modulo operation with 4, and the obtained value is used as the group length type of the file header structure, wherein 0 represents group length type one, 1 represents group length type two, 2 represents group length type three, and 3 represents group length type four.

[0085] (3-3) Set the actual group number (such as group_number) of the file header structure:

[0086] If the group length type is group length type one, the actual group number of the file header structure is set as: the length of the operation point offset address list is divided by the preset maximum group length, and is rounded up.

[0087] If the group length type is group length type two, the actual group number of the file header structure is set as: the length of the operation point offset address list is divided by the preset minimum group length, and is rounded down.

[0088] If the group length type is group length type three, the actual group number of the file header structure is set as the preset group number.

[0089] If the group length type is group length type four, a random integer is generated, and it is required that the generated random number is not less than the minimum group number and is not greater than the maximum group number. The minimum group number is “the length of the operation point offset address list is divided by the preset maximum group length, and is rounded up”, and the maximum group number is “the length of the operation point offset address list is divided by the preset minimum group length, and is rounded down”. The obtained random integer that meets the requirements is used as the actual group number of the file header structure.

[0090] (3-4) Traverse the operation group list of the file header structure, and the index (such as index) starts from the first element of the operation group list (index = 0) until the actual group number (such as group_number) of elements. For each operation group:

[0091] (3-4-1) Set the group length (such as group_len) of the operation group:

[0092] a) If it is the last operation group:

[0093] The group length of the operation group is set as: “the length of the operation point offset address list” minus “the traversal index” multiplied by the step. The step is “the length of the operation point offset address list is divided by the actual group number of the file header structure, and is rounded down”.

[0094] b) For other operation groups:

[0095] The group length of the operation group is set as: the length of the operation point offset address list is divided by the actual group number of the file header structure, and is rounded down

[0096] (3-4-2) Set the group offset address list (e.g. group_offset) of the operation group:

[0097] Traverse the group offset address list of the operation group, the offset address index (e.g. i) starts from the first element of the group offset address list (i = 0) until the group length (e.g. group_len) of the operation group. For each offset address in the group offset address list:

[0098] Set the value of the "offset address index" position of the group offset address list as: the value of the "operation group traversal index multiplied by the step plus the offset address index" (i.e. operation group traversal index x step + offset address index) element of the operation point offset address list of the file header structure. Where the step is "the length of the operation point offset address list divided by the actual group number of the file header structure, and rounded down".

[0099] (3-4-3) Set the head-tail node mode (e.g. group_head_tail_mode) of the operation group:

[0100] Randomly generate a positive integer, take the modulus of the integer with 3, and get the value as the head-tail node mode of the operation group, where 0 represents head-tail node mode one, 1 represents head-tail node mode two, and 2 represents head-tail node mode three.

[0101] (3-4-4) Set the group type (e.g. group_type) of the operation group:

[0102] Randomly generate a positive integer, take the modulus of the integer with 2, and get the value as the group type of the operation group, where 0 represents group type one and 1 represents group type two.

[0103] (3-5) Traverse the operation group list of the file header structure again, the traversal index (e.g. index) starts from the first element of the operation group list (index = 0) until the actual group number (e.g. group_number) of elements. For each operation group:

[0104] (3-5-1) Set the "head node offset address of the group (e.g. group_head_offset)" and "tail node offset address of the group (e.g. group_tail_offset)" of the operation group

[0105] If the head-tail node mode of the operation group is head-tail node mode one:

[0106] a) If it is the first operation group:

[0107] Set the head node offset address of the group (e.g. group_head_offset) to 0.

[0108] Set the group tail offset (e.g., group_tail_offset) of the group to the value of the last element of the group offset list of the current operation group.

[0109] Update the group offset list (e.g., group_offset) of the operation group to be the group offset list of the original operation group with the last element removed.

[0110] Update the group length (e.g., group_len) of the operation group to be the group length (e.g., group_len) of the original operation group minus 1.

[0111] b) If it is the last operation group:

[0112] Set the group head offset (e.g., group_head_offset) of the group to the tail offset of the previous operation group.

[0113] Set the group tail offset (e.g., group_tail_offset) of the group to the size of the source file in bytes;

[0114] c) For other operation groups:

[0115] Set the group head offset (e.g., group_head_offset) of the group to the tail offset of the previous operation group.

[0116] Set the group tail offset (e.g., group_tail_offset) of the group to the value of the last element of the group offset list of the current operation group.

[0117] Update the group offset list (e.g., group_offset) of the operation group to be the group offset list of the original operation group with the last element removed.

[0118] Update the group length (e.g., group_len) of the operation group to be the group length (e.g., group_len) of the original operation group minus 1.

[0119] If the head-tail node mode of the operation group is head-tail node mode two:

[0120] a) If it is the first operation group:

[0121] Set the group head offset (e.g., group_head_offset) of the group to 0.

[0122] Set the group tail offset (e.g., group_tail_offset) of the group to the value of the first element of the group offset list of the next operation group.

[0123] b) If it is the last operation group:

[0124] Set the head node offset address (e.g. group_head_offset) of the group as the tail node offset address of the previous operation group.

[0125] Set the tail node offset address (e.g. group_tail_offset) of the group as the size of the source file (in bytes).

[0126] Update the group length (e.g. group_len) of the operation group as the group length (e.g. group_len) of the original operation group minus 1.

[0127] Update the group offset address list (e.g. group_offset) of the operation group as the group offset address list of the original operation group without the first element.

[0128] c) For other operation groups:

[0129] Set the head node offset address (e.g. group_head_offset) of the group as the tail node offset address of the previous operation group.

[0130] Set the tail node offset address (e.g. group_tail_offset) of the group as the value of the first element of the group offset address list of the next operation group.

[0131] Update the group length (e.g. group_len) of the operation group as the group length (e.g. group_len) of the original operation group minus 1.

[0132] Update the group offset address list (e.g. group_offset) of the operation group as the group offset address list of the original operation group without the first element.

[0133] If the head-tail node mode of the operation group is head-tail node mode three:

[0134] a) If it is the first operation group:

[0135] Set the head node offset address (e.g. group_head_offset) of the group as 0.

[0136] Set the tail node offset address (e.g. group_tail_offset) of the group as "the value of the last element of the group offset address list of the current operation group" plus "the inter-group difference multiplied by a preset ratio". The inter-group difference is the value of the first element of the group offset address list of the next operation group minus the value of the last element of the group offset address list of the current operation group. The preset ratio needs to be greater than 0 and less than 1.

[0137] b) If it is the last operation group:

[0138] Set the head node offset address (e.g. group_head_offset) of the group as the tail node offset address of the previous operation group.

[0139] Set the tail node offset address (e.g. group_tail_offset) of the group as the size of the source file in bytes.

[0140] c) For other operation groups:

[0141] Set the head node offset address (e.g. group_head_offset) of the group as the tail node offset address of the previous operation group.

[0142] Set the tail node offset address (e.g. group_tail_offset) of the group as the value of the last element of the group offset address list of the current operation group plus the inter-group difference value multiplied by a preset ratio. The inter-group difference value is the value of the first element of the group offset address list of the next operation group minus the value of the last element of the group offset address list of the current operation group. The preset ratio must be greater than 0 and less than 1.

[0143] (3-5-2) If the group type of the operation group is group type one, set the group type one head structure of the operation group according to the rules in (4) as follows:

[0144] (3-5-3) If the group type of the operation group is group type two, set the group type two head structure of the operation group according to the rules in (5) as follows:

[0145] (4) Set the group type one head structure of the operation group:

[0146] (4-1) Set the actual number of operation areas (e.g. gap_num) of the group type one head structure as the group length of the operation group.

[0147] (4-2) Set the operation area list of the group type one head structure, the specific process is as follows:

[0148] Traverse the operation area list, and the traversal index (e.g. index) starts from the first element of the operation area list (index = 0) until the actual number of operation areas (e.g. gap_num) of elements. For each operation area:

[0149] a) Set the offset address of the operation area as the value of the "traversal index (e.g. index)"th element of the group offset address list of the operation group;

[0150] b) generate a random integer, which is required to be greater than a preset minimum value (such as 0) and less than the size of the source file (in bytes). The obtained random integer satisfying the requirement is used as the target offset address of the operation area.

[0151] c) generate a random integer, which is required to be greater than a preset minimum value (such as 0) and less than "the size of the source file multiplied by a preset ratio", wherein the preset ratio is greater than 0 and less than 1.

[0152] The obtained random integer satisfying the requirement is used as the operation length of the operation area.

[0153] d) determine whether the "target offset address + operation length" of the operation area exceeds the size of the source file. If it does, the size of the source file minus the size of the target offset address of the operation area is used as the operation length of the operation area.

[0154] (5) Set the group type two-head structure of the operation group:

[0155] (5-1) take the group length of the operation group modulo 2, and the obtained value is used as the swap type (such as swap_type) of the group type two-head structure of the operation group, wherein 0 represents that the swap type is even, and 1 represents that the swap type is odd.

[0156] (5-2) randomly generate a positive integer, take the integer modulo 2, and the obtained value is used as the swap operation mode (such as swap_op_mode) of the group type two-head structure of the operation group, wherein 0 represents swap operation mode one, and 1 represents swap operation mode two.

[0157] (5-3) randomly generate a positive integer, take the integer modulo 3, and the obtained value is used as the pairing mode (such as swap_match_mode) of the group type two-head structure of the operation group, wherein 0 represents pairing mode one, 1 represents pairing mode two, and 2 represents pairing mode three.

[0158] (5-4) if the swap type (such as swap_type) is odd, then the group offset address list of the operation group is used as the odd swap offset address list of the group type two-head structure of the operation group. Otherwise, the swap type is even, and the group offset address list of the operation group is used as the even swap offset address list of the group type two-head structure of the operation group.

[0159] (5-5) set the swap area length (such as swap_len), the actual pairing number (such as match_number), the odd pairing area list, and the even pairing area list. Specifically:

[0160] If the swap type (such as swap_type) is odd:

[0161] a) Constructing a temporary swap offset address list:

[0162] a-1) If the swap operation mode (e.g. swap_op_mode) is of type swap operation mode one:

[0163] The temporary swap offset address list is constructed from the odd swap offset address list.

[0164] a-2) If the swap operation mode (e.g. swap_op_mode) is of type swap operation mode two:

[0165] The temporary swap offset address list is constructed by adding one element at the head and one element at the tail of the odd swap offset address list. Thus the length of the temporary swap offset address list is: odd swap offset address list + 2. And:

[0166] The head element (i.e. the first element) of the temporary swap offset address list is: the "head node offset address of the group" of the operation group.

[0167] The tail element (i.e. the last element) of the temporary swap offset address list is: the "tail node offset address of the group" of the operation group.

[0168] b) Subtracting two by two directly adjacent swap offset addresses in the temporary swap offset address list in order to obtain a set of adjacent differences.

[0169] The length of the obtained set of adjacent differences is: the length of the temporary swap offset address list - 1.

[0170] c) The minimum value of the obtained set of adjacent differences is taken as the swap area length (e.g. swap_len) of the group type two head structure of the operation group.

[0171] d) The length of the obtained set of adjacent differences is divided by 2 and rounded down to be taken as the actual number of matches (e.g. match_number) of the group type two head structure of the operation group.

[0172] e) The odd match area list is set according to the following rules:

[0173] e-1) If the match mode (e.g. swap_match_mode) is of match mode one:

[0174] Traverse the odd match area list, the traverse index (e.g. index) starts from the first element of the odd match area list (index = 0) until the actual number of matches (match_number - 1) elements. For each match area:

[0175] Set the swap address one of the pair zone element to the value of the "index-th" element in the temporary swap offset address list.

[0176] Set the swap address two of the pair zone element to the value of the "(index of the last element of the temporary swap offset address list)-1-index-th" element in the temporary swap offset address list.

[0177] e-2) If the swap match mode (e.g., swap_match_mode) is the second swap match mode:

[0178] Traverse the odd pair zone list, the index (e.g., index) starts from the first element of the odd pair zone list (index = 0) until the actual number of pair elements (match_number-1) elements. For each pair zone:

[0179] Set the swap address one of the pair zone element to the value of the "2*index-th" element in the temporary swap offset address list.

[0180] Set the swap address two of the pair zone element to the value of the "2*index+1-th" element in the temporary swap offset address list.

[0181] e-3) If the swap match mode (e.g., swap_match_mode) is the third swap match mode:

[0182] Set the initial value of the random selection list to be the temporary swap offset address list with the last element removed. Thus the initial length of the random selection list is: the length of the temporary swap offset address list - 1.

[0183] Traverse the odd pair zone list, the index (e.g., index) starts from the first element of the odd pair zone list (index = 0) until the actual number of pair elements (match_number-1) elements. For each pair zone:

[0184] Set the swap address one of the pair zone element to the value of the first element of the random selection list.

[0185] Generate a random positive integer, take the modulus of the integer with the length of the random selection list, and get the value as the random selection index. If the random selection index is 0 (i.e., the first element), add 1 to the random selection index.

[0186] Set the swap address two of the pair zone element to the value of the random selection index position in the random selection list.

[0187] Updating the random selection list and the length of the random selection list: Construct a new random selection list from the elements in the current random selection list except the first element and the element at the random selection index position, and set the new random selection list as the new value of the random selection list. Meanwhile, set "the length of the random selection list-2" as the new length of the random selection list.

[0188] If the swap type (such as swap_type) is even:

[0189] a) Constructing a temporary swap offset address list:

[0190] a-1) If the swap operation mode (such as swap_op_mode) is type swap operation mode one:

[0191] The temporary swap offset address list is constructed by adding an element at the head of the even swap offset address list. Therefore, the length of the temporary swap offset address list is: even swap offset address list + 1. And the head element (i.e. the first element) of the temporary swap offset address list is: the "group head node offset address" of the operation group.

[0192] a-2) If the swap operation mode (such as swap_op_mode) is type swap operation mode two:

[0193] The temporary swap offset address list is constructed by adding an element at the tail of the even swap offset address list. Therefore, the length of the temporary swap offset address list is: even swap offset address list + 1. And the tail element (i.e. the last element) of the temporary swap offset address list is: the "group tail node offset address" of the operation group.

[0194] b) Subtracting the directly adjacent swap offset addresses in the temporary swap offset address list in order to obtain a set of adjacent differences.

[0195] The length of the obtained set of adjacent differences is: the length of the temporary swap offset address list - 1.

[0196] c) The minimum value of the obtained set of adjacent differences is set as the swap area length (such as swap_len) of the group type two head structure of the operation group.

[0197] d) The length of the obtained set of adjacent differences is divided by 2 and rounded down to obtain the actual number of matches (such as match_number) of the group type two head structure of the operation group.

[0198] e) The even pair area list is set according to the following rules:

[0199] e-1) If the match mode (such as swap_match_mode) is match mode one:

[0200] Traverse the even match zone list, with the traverse index (e.g. index) starting at the first element of the even match zone list (index = 0) and going up to the actual number of matches (match_number - 1) elements. For each match zone:

[0201] Set the swap address one of the match zone element to the value of the "traverse index (e.g. index)"th element of the temporary swap offset address list.

[0202] Set the swap address two of the match zone element to the value of the "(index of the last element of the temporary swap offset address list) - 1 - traverse index"th element of the temporary swap offset address list.

[0203] e-2) If the swap match mode (e.g. swap_match_mode) is swap mode two:

[0204] Traverse the even match zone list, with the traverse index (e.g. index) starting at the first element of the even match zone list (index = 0) and going up to the actual number of matches (match_number - 1) elements. For each match zone:

[0205] Set the swap address one of the match zone element to the value of the "2 times traverse index (e.g. index)"th element of the temporary swap offset address list.

[0206] Set the swap address two of the match zone element to the value of the "2 times traverse index (e.g. index) + 1"th element of the temporary swap offset address list.

[0207] e-3) If the swap match mode (e.g. swap_match_mode) is swap mode three:

[0208] Set the initial value of the random selection list to be the temporary swap offset address list with the last element removed. Thus the initial length of the random selection list is: length of the temporary swap offset address list - 1.

[0209] Traverse the even match zone list, with the traverse index (e.g. index) starting at the first element of the even match zone list (index = 0) and going up to the actual number of matches (match_number - 1) elements. For each match zone: Set the swap address one of the match zone element to the value of the first element of the random selection list.

[0210] Generate a random positive integer, take the modulus of the integer with the length of the random selection list, and use the resulting value as the random selection index. If the random selection index is 0 (i.e. the first element), then add 1 to the random selection index.

[0211] The exchange address two of the pairing area element is set to the value of the randomly selected index position in the randomly selected list.

[0212] Updating the randomly selected list and the length of the randomly selected list: the elements in the current randomly selected list except the first element and the randomly selected index position element are sequentially constructed into a new randomly selected list, and the new randomly selected list is taken as the new value of the randomly selected list. At the same time, "the length of the randomly selected list-2" is taken as the length of the new randomly selected list.

[0213] In some embodiments, encrypting the file header structure and forming a second protection file based on the encrypted file header structure and the first protection file include: determining whether the size of the encrypted file header structure is equal to the size of the file header structure before encryption, if yes, writing the encrypted file header structure into the header of the first protection file; if no, constructing a preset size auxiliary header, then writing the auxiliary header into the header of the first protection file, and writing the encrypted file header structure into the current tail of the first protection file, wherein the auxiliary header includes a preset magic number and the size of the encrypted file header structure.

[0214] For example, first, the model header structure of a preset size constructed is encrypted using a preset symmetric encryption algorithm and key, and then it is determined whether the size of the encrypted model header structure is equal to the size of the preset size model header structure before encryption:

[0215] If the sizes are equal, the encrypted model header structure is written into the header of the AI protection model file (such as protected_model.pb). The size of the encrypted model header structure is taken as the model header length (such as protected_model_header_len).

[0216] If the sizes are not equal, a preset size auxiliary header is constructed, which includes two pieces of information, namely a preset magic number and the size of the encrypted model header structure. Then the auxiliary header is written into the header of the AI protection model file (such as protected_model.pb), and the encrypted model header structure is written into the current tail of the AI protection model file (such as protected_model.pb). The "preset size auxiliary header + size of the encrypted model header structure" is taken as the model header length (such as protected_model_header_len).

[0217] 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 include:

[0218] (4-1) Traverse the operation group list of the file header structure, traverse the index (such as index) from the first element of the operation group list (index = 0) to the actual number of elements (such as group_number). For each operation group:

[0219] (4-1-1) If the group type of the operation group is group type one:

[0220] Traverse the operation area list of the group type one header structure of the operation group, traverse the index (such as index) from the first element of the operation area list (index = 0) to the actual number of operation areas of the group type one header structure (such as gap_num). For each operation area:

[0221] (a) If it is the first operation area:

[0222] Get the offset address of the operation area, use the offset address as the read length, then position the source file to the "group header node offset address" of the operation group, read the data of the size of "operation area offset address minus group header node offset address" to the temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0223] Position the source file to the target offset address of the current operation area, read the data of the size of the operation length of the current operation area to the temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0224] (b) If it is the last operation area: use the offset address of the operation area as the current operation area offset address, and use the offset address of the operation area before the operation area as the auxiliary offset address. Then:

[0225] Position the source file to the auxiliary offset address, read the data of the size of "current operation area offset address-auxiliary offset address" to the temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0226] Position the source file to the target offset address of the current operation area, read the data of the size of the operation length of the current operation area to the temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0227] Locate the source file to the offset address of the last operation region, read data of "tail node offset address of the group - offset address of the last operation region" length to a temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0228] (c) For other operation regions: take the offset address of the operation region as the current operation region offset address, and take the offset address of the operation region in front of the operation region as the auxiliary offset address. Then:

[0229] Locate the source file to the auxiliary offset address, read data of "current operation region offset address - auxiliary offset address" length to a temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0230] Locate the source file to the target offset address of the current operation region, read data of the operation length of the current operation region to a temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0231] (4-1-2) If the group type of the operation group is group type two:

[0232] Locate the source file to "head node offset address of the group" of the operation group, read data of "tail node offset address of the group - head node offset address of the group" length of the operation group to a temporary buffer, and then write the data of the buffer to the current tail of the protection file (such as protected_model.pb).

[0233] (4-2) Set the initial value of the temporary auxiliary length as the file header length.

[0234] Then traverse the operation group list of the file header structure again, and traverse the index (such as index) from the first element of the operation group list (index = 0) to the actual number of groups (such as group_number) of elements. For each operation group:

[0235] (4-2-1) If the group type of the operation group is group type one:

[0236] Traverse the operation region list of the group type one header structure of the operation group, and traverse the index (such as index) from the first element of the operation region list (index = 0) to the actual number of operation regions (such as gap_num) of the group type one header structure. For each operation region:

[0237] Update the temporary auxiliary length as: the original temporary auxiliary length + the operation length of the current operation region.

[0238] (4-2-2) If the group type of the operation group is group type two:

[0239] (a) If the swap type (e.g., swap_type) of the group type two header structure of the operation group is odd: set the temporary match list to the odd match list of the group type two header structure of the operation group. Otherwise, the swap type (e.g., swap_type) of the group type two header structure of the operation group is even: set the temporary match list to the even match list of the group type two header structure of the operation group.

[0240] (b) Traverse the temporary match list, starting with the first element of the temporary match list (index = 0) and ending with the actual number of matches (match_number - 1) of the file header structure. For each match:

[0241] Position the protection file at the swap address one of the match element plus the temporary offset, and read the swap length of the group type two header structure of the operation group into temporary buffer one.

[0242] Position the protection file at the swap address two of the match element plus the temporary offset, and read the swap length of the group type two header structure of the operation group into temporary buffer two.

[0243] Position the protection file at the swap address one of the match element plus the temporary offset, and then write the data in temporary buffer two, writing the data length of the swap length of the group type two header structure of the operation group.

[0244] Position the protection file at the swap address two of the match element plus the temporary offset, and then write the data in temporary buffer one, writing the data length of the swap length of the group type two header structure of the operation group.

[0245] In some embodiments, the file processing method can further include obtaining the source file, the source file including an artificial intelligence source model file.

[0246] In some embodiments, after generating the third protection file, the file processing method can further include performing publishing and deployment based on the third protection file.

[0247] According to an embodiment of the present disclosure, a source file is randomly damaged by a constructed file header structure, and a random damage rule is written into a source file header after being encrypted. Since the source file is randomly damaged, the content damaged each time is different for the same source file, and thus the protected file after damage is also different, thereby maximizing the confidentiality and security of the source file protection. Meanwhile, since the entire source file is not encrypted, the demand for computing resources is reduced while the source file is protected.

[0248] Figure 2 is a flow chart illustrating a file processing method according to an embodiment of the present disclosure. As shown in Figure 2 , the file processing method comprises the following steps S210 to S230.

[0249] In step S210, a protected file is received, 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 group type.

[0250] In step S220, the first information of the protected file is verified based on a preset file header structure.

[0251] As shown in Figure 3 , verifying the first information of the protected file based on a preset file header structure comprises the following steps S221 to S223.

[0252] In step S221, the encrypted file header structure is derived from the header of the protected file.

[0253] In step S222, the encrypted file header structure is decrypted using a preset symmetric encryption algorithm and key.

[0254] In step S223, the decrypted file header structure is verified based on a preset file header structure.

[0255] Specifically, in the present embodiment, the corresponding verification is performed according to the encryption manner of the file header structure. The present embodiment verifies the header of the protected file by using the following manner:

[0256] The auxiliary header of the preset size is read from the header of the protected file, and it is judged whether the magic number of the auxiliary header is the same as the preset magic number:

[0257] If same, locate the protected file to the auxiliary header, read data of the specified size to the temporary buffer according to the "size of encrypted file header structure" in the auxiliary header as the encrypted file header structure. Add the "preset size of auxiliary header" and the "size of encrypted file header structure" as the file temporary header length (such as protected_model_header_len).

[0258] If not same, locate to the header of the protected file, read the preset size of the file header structure to the temporary buffer as the encrypted file header structure. Add the preset size of the file header structure as the file temporary header length (such as protected_model_header_len).

[0259] Step S220, in response to the first information of the protected file being verified, derive the source file based on the second information of the protected file.

[0260] In some embodiments, as shown in Figure 4 Deriving the source file based on the second information of the protected file includes steps S231 and S232.

[0261] In step S231, derive the processed source file from the tail of the protected file.

[0262] In step S232, decode the source file from the processed source file according to the file header structure, and store the source file to the target buffer.

[0263] In addition, in some embodiments, deriving the source file based on the second information of the protected file includes:

[0264] Decrypt the encrypted file header structure in the temporary buffer using a preset symmetric encryption algorithm and key to obtain a decrypted file header structure. Determine whether the protection magic number in the decrypted file header structure is same as the preset protection magic number: if same, pre-allocate the target file buffer, otherwise, prompt invalid file and exit.

[0265] Pre-allocate the target file buffer, specifically including:

[0266] (1) Set the initial value of the total length of the temporary operation area to 0.

[0267] (2) Traverse the operation group list of the file header structure, and traverse the index (such as index) from the first element of the operation group list (index = 0) to the actual number of elements (such as group_number). For each operation group:

[0268] (a) If the group type of the operation group is group type one:

[0269] Traverse the operation area list of the group type one header structure of the operation group, traverse index (such as index) from the first element of the operation area list (index = 0) to the actual operation area number (such as gap_num) of the group type one header structure. For each operation area:

[0270] Update the temporary operation area total length as: the original temporary operation area total length + the operation length of the current operation area.

[0271] (3) Pre-allocate a target file buffer, whose size is at least: the size of the protection file - the file temporary header length - the temporary operation area total length.

[0272] Initialize the pre-allocated target file buffer (such as all initialized to 0x00).

[0273] Decode the original file from the protection file and store it to the target file buffer. The specific process is as follows:

[0274] Set the temporary auxiliary length initial value as the model temporary header length.

[0275] (4-2) Traverse the operation group list of the file header structure, traverse index (such as index) from the first element of the operation group list (index = 0) to the actual group number (such as group_number) elements. For each operation group:

[0276] (4-2-1) If the group type of the operation group is group type one:

[0277] Traverse the operation area list of the group type one header structure of the operation group, traverse index (such as index) from the first element of the operation area list (index = 0) to the actual operation area number (such as gap_num) of the group type one header structure. For each operation area:

[0278] (a) If it is the first operation area:

[0279] Take the offset address of the operation area as the current operation area offset address, and take the operation length of the operation area as the current operation area operation length. Then:

[0280] a\ Position the protection file to "the group header node offset address of the operation group + the temporary auxiliary length", and then read "(the current operation area offset address + the temporary auxiliary length) - (the group header node offset address + the temporary auxiliary length)" size of data to the pre-allocated target file buffer.

[0281] b\ update the temporary auxiliary length as: the original temporary auxiliary length + the operation length of the current operation area.

[0282] (b) if it is the last operation area:

[0283] set the offset address of the operation area as the current operation area offset address, set the operation length of the operation area as the current operation area operation length, and set the offset address of the "previous operation area of the operation area + temporary auxiliary length" as the auxiliary offset address. Then:

[0284] a\ position the protection file file to the "auxiliary offset address", read data of "current operation area offset address + temporary auxiliary length - auxiliary offset address" long to the pre-allocated target file buffer.

[0285] b\ position the protection file file to "current operation area offset address + temporary auxiliary length + current operation area operation length", read data of "group tail node offset address + temporary auxiliary length + current operation area operation length - (current operation area offset address + temporary auxiliary length + current operation area operation length)" long to the pre-allocated target file buffer.

[0286] c\ if the current operation group is not the last valid operation group of the operation group list of the file header structure:

[0287] update the temporary auxiliary length as: the original temporary auxiliary length + the operation length of the current operation area.

[0288] (c) for other operation areas:

[0289] set the offset address of the operation area as the current operation area offset address, set the operation length of the operation area as the current operation area operation length, and set the offset address of the "previous operation area of the operation area + temporary auxiliary length" as the auxiliary offset address. Then:

[0290] a\ position the protection file file to the "auxiliary offset address", read data of "current operation area offset address + temporary auxiliary length - auxiliary offset address" long to the pre-allocated target file buffer.

[0291] b\ update the temporary auxiliary length as: the original temporary auxiliary length + the operation length of the current operation area.

[0292] (4-2-2) if the group type of the operation group is group type two:

[0293] position the protection file file to "group head node offset address of the operation group" + temporary auxiliary length, read data of "group tail node offset address - group head node offset address" long of the operation group to the temporary buffer, and then write the data of the buffer to the pre-allocated target file buffer.

[0294] (4-3) Again traverse the operation group list of the file header structure, traverse the index (such as index) from the first element of the operation group list (index=0) to the actual group number (such as group_number) elements. For each operation group:

[0295] (4-2-1) If the group type of the operation group is group type one: continue to traverse the next operation group.

[0296] (4-2-2) If the group type of the operation group is group type two:

[0297] (a) If the swap type (such as swap_type) of the group type two header structure of the operation group is odd: set the temporary matching area list to the odd matching area list of the group type two header structure of the operation group, otherwise the swap type (such as swap_type) of the group type two header structure of the operation group is even: set the temporary matching area list to the even matching area list of the group type two header structure of the operation group.

[0298] (b) Traverse the temporary matching area list, traverse the index (such as index) from the first element of the temporary matching area list (index=0) to the actual matching number (match_number-1) elements of the file header structure. For each matching area:

[0299] Position the target file buffer to the swap address one of the matching area element, read the data of the "swap area length of the group type two header structure of the operation group" size to the temporary buffer one.

[0300] Position the target file buffer to the swap address two of the matching area element, read the data of the "swap area length of the group type two header structure of the operation group" size to the temporary buffer two.

[0301] Position the target file buffer to the swap address one of the matching area element, and then write the data in the temporary buffer two, the data length is "swap area length of the group type two header structure of the operation group".

[0302] Position the target file buffer to the swap address two of the matching area element, and then write the data in the temporary buffer one, the data length is "swap area length of the group type two header structure of the operation group".

[0303] Figure 5 Take the source file as an AI source file file as an example, and the implementation process of the file processing method in this embodiment is shown.

[0304] As Figure 5As shown, in the protection of the AI source model file, the AI source model file is acquired, an empty AI protection model file is created, a model header structure is constructed based on a group type, the constructed model header structure is encrypted and written into the header of the AI protection model file, the source model is read, the AI protection model file is constructed according to the information of the model header structure, the processed AI protection model file is published and used for actual deployment. When the AI source model file is used, the protection model header is verified, the original model is decoded from the protection model file and stored in a target model buffer. In the protection process of the AI model in the embodiment, the entire AI model is not encrypted, but the AI model is randomly damaged, and the random damage rule is encrypted and written into the AI model header. Since the AI model is randomly damaged, the content of each damage is different for the same AI model, so that the AI protection model after damage is also different, thereby maximizing the confidentiality and security of the AI model protection. At the same time, since the entire AI model is not encrypted, the demand for computing resources is reduced while the AI model is protected, especially for the end device deployed in the limited computing resource, the speed of the AI model before inference is improved. The method of the embodiment is suitable for protecting any AI model, and does not limit the software and hardware environment and scene, and has strong universality.

[0305] Figure 6 is a block diagram illustrating an electronic device according to an embodiment of the disclosure. As shown in Figure 6 the embodiment provides an electronic device 101, which includes a processor 1001 and a memory 1002; the memory 1002 is configured to store a computer program; and the processor 1001 is configured to execute the computer program stored in the memory 1002, so that the electronic device 101 performs each step of the file processing method as described in the above embodiments. Since the specific implementation process of each step of the file processing method has been described in detail in the above embodiments, it will not be repeated here.

[0306] The processor 1001 is a CPU (Central Processing Unit, Central Processing Unit). The memory 1002 is connected with the processor 1001 through a system bus and completes mutual communication. The memory 1002 is configured to store a computer program, and the processor 1001 is configured to run the computer program, so that the processor 1001 executes the file processing method. The memory 1002 can include a random access memory (RAM) and can also include a non-volatile memory such as at least one disk memory.

[0307] In addition, the embodiment further provides a computer readable storage medium, which stores a computer program. The computer program is executed by the processor 1001 to implement the file processing method. The file processing method has been described in detail above, and will not be described here.

[0308] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by computer program related hardware. The aforementioned computer program can be stored in a computer readable storage medium. The program is executed to perform the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes ROM, RAM, magnetic disc or optical disc and various storage medium that can store program codes.

[0309] In summary, the present application does not encrypt the entire source file (such as an AI file), but randomly destroys the source file by constructing a file header structure, and writes the encrypted random destruction rule into the source file header. Since the source file is randomly destroyed, the content of each destruction is different for the same source file, so the protected 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 the limited computing resource, the speed of the source file protection before inference is improved. The method of the present application is suitable for protecting AI file, various application documents, and does not limit the hardware and software environment and scene, and has strong universality. Therefore, the present application effectively overcomes the shortcomings of the prior art and has high industrial utilization value.

[0310] The above embodiments only exemplarily illustrate the principles and effects of the present application, and are not used to limit the present application. Any person skilled in the art can modify or change the above embodiments without departing from the spirit and scope of the present application. Therefore, all equivalent modifications or changes completed by those skilled in the art without departing from the spirit and technical idea of the present application should be covered by the claims of the present 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 group type; 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 process of constructing a file header structure associated with the source files based on group type includes: generating a set of preset number of random numbers; grouping the source files according to preset rules based on the generated random numbers, and randomly determining the group type for each group of source files; and constructing a corresponding file header structure for each group based on the group type of each group.

2. The file processing method according to claim 1, characterized in that, The file header structure consists of a preset protection magic number, grouping mode, operation point offset address list, actual number of groups, group length type, and operation group list.

3. The file processing method according to claim 2, characterized in that, Each operation group in the operation group list consists of a group length, a group offset address list, a head and tail node pattern, a head node offset address, a tail node offset address, a group type, a one-head structure for the group type, and a two-head structure for the group type.

4. The file processing method according to claim 1, characterized in that, The group type is a one-head structure consisting of the actual number of operation areas and the operation area list. Each operation area in the operation area list includes an offset address, a target offset address, and an operation length. The step of constructing the file header structure corresponding to each group based on the group type includes: A first set of random numbers and a second set of random numbers are randomly generated, wherein the first set of random numbers corresponds to the offset address of the operation area in the source file, and the second set of random numbers corresponds to the target offset address of the operation area in the source file; A third set of random numbers is inserted after the offset address of each of the operation areas as the operation length, wherein the starting position of the third set of random numbers is determined by the target offset address of the operation area.

5. The file processing method according to claim 1, characterized in that, The group type is a two-headed structure consisting of 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. The methods for constructing the file header structure include: Generate a 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.

6. 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.

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: Receive a protected file, 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 group type, which includes generating a set of preset number of random numbers, grouping the source files according to preset rules according to the generated random numbers, randomly determining a group type for each group of source files, and constructing a file header structure corresponding to each group according to the group type of each group; 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 claim 9.

Citation Information

Patent Citations

  • File processing method and file processing device

    CN104732159A

  • Method and equipment for generating encrypted file

    CN112241538A