File encryption method, device, electronic device and storage medium
By only encrypting the frame header of the file, the problem of large amount of file data after encryption in the prior art is solved, and the effects of fast encryption and resource saving are achieved.
Patent Information
- Application Number
- CN202110349053.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-31
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2041-03-31
AI Technical Summary
After the existing file encryption method is encrypted, the encrypted file data is large, resulting in waste of transmission and storage resources.
By determining the data frame to be encrypted from multiple data frames of the file to be encrypted and only encrypting its frame header, the encrypted file is obtained, and the frame body is avoided, thereby reducing the amount of data in the encrypted file.
It realizes fast encryption, saves network transmission and storage resources, and reduces CPU overhead of electronic devices.
Smart Images

Figure CN113051592B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of encryption technology, and more specifically, to a file encryption method, device, electronic device and storage medium. Background Art
[0002] With the development of network technology, information security has become a key concern. If files are transmitted or stored in plain text over the network, there is a high risk of file leakage. To prevent file leakage, encrypted files are usually encrypted. However, existing encryption methods often result in a large amount of data after encryption, resulting in a waste of transmission and storage resources. Summary of the Invention
[0003] In view of the above problems, the present application proposes a file encryption method, device, electronic device and storage medium, which can solve the above problems.
[0004] In a first aspect, an embodiment of the present application provides a file encryption method for obtaining a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each data frame in the multiple data frames includes a frame header and a frame body; determining the data frame to be encrypted from the multiple data frames, and obtaining the frame header included in the data frame to be encrypted as the frame header to be encrypted; encrypting the frame header to be encrypted to obtain an encrypted file.
[0005] In second aspect, an embodiment of the present application provides a file encryption device, a file to be encrypted acquisition module, used to obtain the file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each data frame in the multiple data frames includes a frame header and a frame body; the frame header to be encrypted acquisition module is used to determine the data frame to be encrypted from the multiple data frames, and obtain the frame header included in the data frame to be encrypted as the frame header to be encrypted; the file encryption module is used to encrypt the frame header to be encrypted to obtain an encrypted file.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the above method.
[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which program code is stored, and the program code can be called by a processor to execute the above method.
[0008] In the file encryption method provided in this embodiment, a file to be encrypted is obtained, and the file to be encrypted includes multiple data frames, each of the multiple data frames includes a frame header and a frame body, and then the data frame to be encrypted is determined from the multiple data frames, and the frame header included in the data frame to be encrypted is obtained as the frame header to be encrypted, the frame header to be encrypted is encrypted to obtain an encrypted file, the frame header to be encrypted is encrypted, and the frame body is not encrypted. The CPU overhead of the electronic device is small, fast encryption can be achieved, and the data volume of the encrypted file is small, which can save network transmission resources and storage resources.
[0009] These and other aspects of the present application will become more readily apparent from the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0011] Figure 1 A schematic diagram showing a flow chart of a file encryption method provided by an embodiment of the present application is shown;
[0012] Figure 2 A schematic diagram showing a flow chart of a file encryption method provided by another embodiment of the present application is shown;
[0013] Figure 3 A schematic diagram showing a flow chart of a file encryption method provided by another embodiment of the present application is shown;
[0014] Figure 4 A traversal diagram provided by an embodiment of the present application is shown;
[0015] Figure 5 A schematic diagram of a process flow of a file encryption method provided in yet another embodiment of the present application is shown;
[0016] Figure 6 A schematic diagram showing a flow chart of a file encryption method provided by yet another embodiment of the present application is shown;
[0017] Figure 7 A schematic diagram of a separation process provided by an embodiment of the present application is shown;
[0018] Figure 8 A schematic diagram of a separation process provided by another embodiment of the present application is shown;
[0019] Figure 9 A schematic diagram of out-of-order processing provided by an embodiment of the present application is shown;
[0020] Figure 10 A schematic diagram of an encrypted file according to an embodiment of the present application is shown;
[0021] Figure 11 A block diagram of a file encryption device provided by an embodiment of the present application is shown;
[0022] Figure 12 is a block diagram of an electronic device for executing a file encryption method according to an embodiment of the present application;
[0023] Figure 13 A storage unit for storing or carrying program codes for implementing the file encryption method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0025] With the development of network technology, information security has become a key concern. If files are transmitted or stored in plain text over the network, there is a high risk of file leakage. To prevent file leakage, encrypted files are usually encrypted. However, existing encryption methods encrypt the entire file, which often results in a large amount of data after encryption, resulting in a waste of transmission and storage resources.
[0026] To address the above technical issues, the inventors, after extensive research, have discovered and proposed a file encryption method, device, electronic device, and storage medium. These methods identify a data frame to be encrypted from multiple data frames in a file to be encrypted, obtain a frame header included in the data frame as the frame header to be encrypted, encrypt the frame header to obtain an encrypted file, and encrypt only the frame header of the file to be encrypted. This reduces the data size of the encrypted file and conserves transmission and storage resources. The specific file encryption method is described in detail in subsequent embodiments.
[0027] Figure 1 The flowchart of the file encryption method provided by an embodiment of the present application is shown, which only encrypts the frame header of the file to be encrypted, so that the data volume of the encrypted file is small. In a specific embodiment, the file encryption method is applied to Figure 11 The file encryption device 100 and the electronic device 200 equipped with the file encryption device 100 are shown. Figure 12 ). This embodiment will take the file encryption method applied to an electronic device as an example to illustrate the specific process of this embodiment. Of course, it can be understood that the electronic device applied in this embodiment can be a tablet computer, desktop computer, laptop computer, mobile phone, etc., which is not limited here. Figure 1 The process shown in FIG. 1 is described in detail. The file encryption method may specifically include the following steps:
[0028] Step S110: Acquire a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each of the multiple data frames includes a frame header and a frame body.
[0029] The file to be encrypted is obtained. The file to be encrypted may be a file locally stored or collected by the electronic device, or a file downloaded from a server connected to the electronic device.
[0030] Optionally, the file to be encrypted may be an audio file, an image file, a video file, etc. When the file to be encrypted is an audio file, the file to be encrypted includes multiple audio frames; when the file to be encrypted is an image file, the file to be encrypted includes multiple image frames; when the file to be encrypted is a video file, the file to be encrypted includes multiple audio frames and multiple image frames.
[0031] Optionally, the file to be encrypted may be a file encoded using a preset encoding method, for example, the preset encoding method is Free Lossless Audio Codec (FLAC), and the file to be encrypted may be a FLAC file encoded using FLAC.
[0032] Step S120: Determine a data frame to be encrypted from the multiple data frames, and obtain a frame header included in the data frame to be encrypted as a frame header to be encrypted.
[0033] Traverse the file to be encrypted and determine the data frame to be encrypted from multiple data frames, where the data frame to be encrypted may be part or all of the multiple data frames, and then obtain the frame header of the data frame to be encrypted as the frame header to be encrypted. When the data frame to be encrypted is part of multiple data frames, obtain the part of the frame header as the frame header to be encrypted; when the data frame to be encrypted is all data frames, obtain all the frame headers as the frame header to be encrypted.
[0034] Depending on the importance of the files to be encrypted, users can set different encryption levels for different files to be encrypted. Based on the encryption level, data frames to be encrypted are determined from multiple data frames. The encryption level is positively correlated with the number of data frames to be encrypted. That is, a higher encryption level results in a greater number of data frames to be encrypted from the multiple data frames, such as all data frames. A lower encryption level results in a smaller number of data frames to be encrypted from the multiple data frames, such as a portion of the data frames.
[0035] When the data frame to be encrypted may be a part of multiple data frames, in one embodiment, a part is randomly obtained from the multiple data frames as the data frame to be encrypted, so that the data frame to be encrypted can be obtained faster.
[0036] In another embodiment, parts of multiple data frames are obtained as data frames to be encrypted at certain intervals, and data frames to be encrypted are obtained evenly in the entire file to be encrypted, so as to reduce large-scale leakage of the file to be encrypted.
[0037] Step S130: encrypt the frame header to be encrypted to obtain an encrypted file.
[0038] In one embodiment, the encrypted frame header is encrypted according to a preset encryption algorithm to obtain an encrypted file. Optionally, the preset encryption algorithm may be, but is not limited to, a Secure Hash Algorithm (SHA), a Hash-based Message Authentication Code (HMAC), or the like.
[0039] In another embodiment, multiple frame headers to be encrypted are processed in a random order to disrupt the order of the multiple frame headers to be encrypted in the file to be encrypted, thereby obtaining an encrypted file.
[0040] In other implementations, a preset encryption algorithm and scrambling can be combined to encrypt the header to be encrypted. Specifically, the preset encryption algorithm is first used to encrypt the header to be encrypted, and then the encrypted header to be encrypted is scrambled to obtain the encrypted file. Alternatively, the scrambled header to be encrypted is first performed, and then the scrambled header to be encrypted is encrypted to obtain the encrypted file.
[0041] In the file to be encrypted, the encrypted frame header of the data frame to be encrypted is encrypted. Each data frame includes a frame body arranged after the frame header. When reading the data frame, it is necessary to read them one by one in the reading order from the frame header to the frame body. Since the frame header is encrypted, the information carried in the frame header cannot be read. Therefore, it is also impossible to continue to read the information carried in the frame body after the frame header in the reading order, thereby realizing the encryption of the file to be encrypted.
[0042] When the data frame to be encrypted is part of multiple data frames, the part of the data frame to be encrypted in the encrypted file is encrypted, so that the part of the data frame in the encrypted file is invisible and the eavesdropper cannot read the complete file, thereby achieving encryption. Moreover, the frame header to be encrypted is part of multiple frame headers. Therefore, by encrypting part of the frame header, an encrypted file with a smaller data amount can be obtained.
[0043] When the data frames to be encrypted are all of the multiple data frames, all the data frames to be encrypted in the encrypted file are encrypted, so that all the data frames in the encrypted file are invisible and the eavesdropper cannot read the file at all, thereby achieving encryption.
[0044] In the file encryption method provided in this embodiment, a file to be encrypted is obtained, and the file to be encrypted includes multiple data frames, each of the multiple data frames includes a frame header and a frame body, and then the data frame to be encrypted is determined from the multiple data frames, and the frame header included in the data frame to be encrypted is obtained as the frame header to be encrypted, the frame header to be encrypted is encrypted to obtain an encrypted file, the frame header to be encrypted is encrypted, and the frame body is not encrypted. The processor overhead of the electronic device is small, fast encryption can be achieved, and the data volume of the encrypted file is small, which can save network transmission resources and storage resources.
[0045] Based on the above embodiment, this example provides a file encryption method for determining a data frame to be encrypted among multiple data frames. Figure 2 A flowchart of a file encryption method according to another embodiment of the present invention is shown. Figure 2 , the file encryption method may specifically include the following steps:
[0046] Step S210: Acquire a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each of the multiple data frames includes a frame header and a frame body.
[0047] The detailed description of step S210 can be found in step S110 and will not be repeated here.
[0048] Step S220: traverse the file to be encrypted in a jump manner according to the traversal interval, and determine the data frame to be encrypted from the multiple data frames.
[0049] To improve access efficiency to the file to be encrypted, the file to be encrypted can be traversed in a jump traversal manner, for example, using a jump search algorithm. When the traversal accesses a frame header identifier, the location of the frame header can be determined, and the data frame corresponding to the frame header can be determined as the data frame to be encrypted. It is understood that the data frame accessed during the traversal is the data frame to be encrypted.
[0050] When the data frames to be encrypted include some data frames in the file to be encrypted, the file to be encrypted is traversed in a jump manner according to the traversal interval. The data frames obtained during the traversal are used as the data frames to be encrypted, and the data frames skipped according to the traversal interval are used as non-encrypted data frames. For example, the multiple data frames include at least data frame 1, data frame 2, and data frame 3. During the jump traversal, the process jumps from data frame 1 to data frame 3, and data frames 1 and 3 are determined to be the data frames to be encrypted, while data frame 2 is determined to be the non-encrypted data frame. During encryption, only the encrypted frame headers of the data frames to be encrypted are encrypted, while the non-encrypted data frames do not need to be encrypted.
[0051] To improve access efficiency, when the data frames to be encrypted include all the data frames in the file to be encrypted, a skip traversal method can also be used. The traversal interval can be the length of the data frame body. During traversal, the frame body can be skipped to the header of the next data frame, achieving rapid positioning of all data frames.
[0052] Before traversing the file to be encrypted, it is necessary to first determine the traversal interval. In one embodiment, the encryption level can be determined based on user experience and the encryption requirements of the data frame to be encrypted. A correspondence between the encryption level and the traversal interval, i.e., a preset correspondence, can be set. Based on the preset correspondence, the traversal interval corresponding to the encryption level is determined. For example, the encryption levels may include a first encryption level and a second encryption level, where the first encryption level is higher than the second encryption level, and the traversal interval A is shorter than the traversal interval B. The preset correspondence includes at least a correspondence between the first encryption level and the traversal interval A, and a correspondence between the second encryption level and the traversal interval B.
[0053] In another embodiment, when each data frame in the file to be encrypted is a compressed data frame, the traversal interval may be determined according to the encryption level, the encoding method, and the length of the data frame before encoding and compression.
[0054] In another embodiment, the traversal interval may be pre-set, and the user may adjust it according to the type of the file to be encrypted and the encryption requirements.
[0055] Step S230: Acquire a frame header included in the data frame to be encrypted as a frame header to be encrypted.
[0056] Step S240: encrypt the frame header to be encrypted to obtain an encrypted file.
[0057] For the detailed description of steps S230 to S240 , please refer to steps S120 to S130 , which will not be repeated here.
[0058] The file encryption method provided in this embodiment determines the data frame to be encrypted from multiple data frames by traversing the file to be encrypted at a traversal interval, and determines the frame header of the data frame to be encrypted as the frame header to be encrypted, encrypts the frame header to be encrypted, and obtains the encrypted file. By traversing in a jumping manner, the data frame to be encrypted can be quickly located, thereby speeding up the encryption process.
[0059] Based on the above embodiment, this embodiment provides a file encryption method for determining a traversal interval, and then traversing multiple data frames at the traversal interval to uniformly obtain multiple data frames to be encrypted therefrom, thereby achieving uniform encryption and improving the security of encryption, wherein the multiple data frames in the file to be encrypted are data frames obtained by encoding the frame body. Figure 3A flowchart of a file encryption method according to another embodiment of the present invention is shown. Figure 3 , the file encryption method may specifically include the following steps:
[0060] Step S310: Acquire a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each of the multiple data frames includes a frame header and a frame body.
[0061] The detailed description of step S310 can be found in step S110 and will not be repeated here.
[0062] Step S320: Determine a first data frame to be encrypted from the multiple data frames, and obtain a frame length of the first data frame to be encrypted before encoding as a first frame length.
[0063] In one embodiment, the file to be encrypted is traversed, and the first data frame among the multiple data frames is accessed as the first data frame to be encrypted. Figure 4 As shown, the file to be encrypted includes at least an information header, data frame 1 and data frame 2, wherein data frame 1 includes frame header 1 and frame body 1, and data frame 2 includes frame header 2 and frame body 2. The file to be encrypted is traversed starting from the information header. When traversing to frame header 1, data frame 1 corresponding to frame header 1 is determined as the first data frame.
[0064] In another embodiment, the file to be encrypted is traversed, and the first data frame accessed among the multiple data frames is used as the first data frame to be encrypted. It is understood that the first data frame to be encrypted may not be the first data frame among the multiple data frames, but may also be the second or third data frame among the multiple data frames. For example, based on the importance of the file to be encrypted, the user sets different encryption levels for different files to be encrypted. Based on the encryption levels, N data frames to be encrypted are determined from the file to be encrypted. Therefore, the encryption requirement can be met if the number of data frames obtained after the first data frame to be encrypted among the multiple data frames is greater than or equal to N-1.
[0065] The information header includes the frame length of each data frame before encoding. Therefore, the frame length of the first data frame to be encrypted before encoding can be obtained from the information header as the first frame length. It should be noted that the first frame length includes the sum of the length of the frame header and the frame body of the first data frame to be encrypted before encoding, that is, Figure 4 The sum of the lengths of frame header 1 and frame body 1.
[0066] Step S330: Determine a first traversal interval according to the first frame length, traverse the file to be encrypted according to the first traversal interval, and determine a second data frame to be encrypted from the multiple data frames.
[0067] In this embodiment, first, an encoding method for encoding a data frame is obtained. For example, the encoding method may be FLAC, American Standard Code for Information Interchange (ASCII), or the like.
[0068] Then, the first traversal interval is determined according to the encoding method and the first frame length. Optionally, a correspondence between multiple encoding methods, multiple frame lengths and multiple traversal intervals is pre-established, that is, a preset mapping relationship. Based on the preset mapping relationship, the first traversal interval corresponding to the encoding method and the first frame length is determined. For example, when the encoding method is FLAC encoding, the data frame is usually compressed to 50% of the frame length (that is, the frame length before encoding). Since the length of the frame header is usually 10% of the frame length and the length of the frame body is 40% of the original frame length, the preset mapping relationship between FLAC encoding, frame length and traversal interval can be expressed by the following formula: l=L*40%, where l is the traversal interval and L is the frame length. When L1 is the first frame length, the first traversal interval l1 is as follows: Figure 4 shown.
[0069] Then, the file to be encrypted is traversed according to the first traversal interval, and the second data frame to be encrypted is determined from the multiple data frames. Figure 4 , continue to traverse along the traversal direction, after jumping to the first traversal interval, access frame header 2, and then the data frame 2 corresponding to the frame header 2 is used as the second data frame to be encrypted.
[0070] It should be noted that, in addition to the obtained data frame to be encrypted being the entirety of multiple data frames. It can also be that, when the encryption level is low, the data frame to be encrypted is part of multiple data frames, that is, a larger first traversal interval can be set, and the frame body and part of the data frame of the first data frame can be skipped during traversal, so that the obtained data frame to be encrypted is part of multiple data frames. Continuing with the above example, when the encoding method is FLAC encoding, the frame body length is 40% of the original frame length, the number of skipped data frames is n, and the length of the skipped n data frames is 50% L*n, then the preset mapping relationship between FLAC encoding, frame length and traversal interval can be expressed by the following formula: l = L*(40%+50%n). Combined with Figure 4 , taking n as 1 as an example, skipping the frame body of the first data frame and data frame 2, l = L*90%, that is, the first traversal interval skips the frame body of the first data frame (40%) and data frame 2 (50%), then the second data frame to be encrypted is Figure 4 Data frame 3 in .
[0071] It should also be noted that when the information differences between multiple data frames are small, for example, multiple data frames are multiple audio frames, and the timbre, pitch, speaking speed, etc. of the sound in multiple audio frames change little, the difference between the multiple audio frames is small, and the frame lengths of the data frames with small differences before compression are almost the same. Therefore, when traversing the entire file to be encrypted, the same traversal interval is used, that is, the first traversal interval is used to traverse the entire file to be encrypted.
[0072] Step S340: Determine the first data frame to be encrypted and the second data frame to be encrypted as the data frames to be encrypted.
[0073] It should be noted that the number of multiple data frames is not limited to Figure 4 The data frame in the encryption process may also be more data frames. Therefore, the data frame to be encrypted is not limited to the first data frame to be encrypted and the second data frame to be encrypted, and may also be more data frames.
[0074] Step S350: Obtain a frame header included in the data frame to be encrypted as a frame header to be encrypted, and encrypt the frame header to be encrypted to obtain an encrypted file.
[0075] The detailed description of step S350 can be found in step S110 and will not be repeated here.
[0076] In this embodiment, a first encrypted data frame is determined from multiple data frames, and the frame length of the first data frame to be encrypted before encoding is obtained as the first frame length. The first traversal interval is determined according to the first frame length. Then, the file to be encrypted is traversed according to the first traversal interval to obtain the second data frame to be encrypted. The obtained first data frame to be encrypted and the second data frame to be encrypted are used as the data frames to be encrypted, and the encrypted frame headers of the data frames to be encrypted are encrypted, so that the encrypted file can be quickly obtained.
[0077] Based on the above embodiment, this embodiment provides a file encryption method for traversing a file to be encrypted according to different traversal intervals, obtaining a data frame to be encrypted, and encrypting the encrypted frame header of the data frame to be encrypted to obtain an encrypted file. Figure 5 A flowchart of a file encryption method according to another embodiment of the present invention is shown. Figure 5 , the file encryption method may specifically include the following steps:
[0078] Step S410: Acquire a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each of the multiple data frames includes a frame header and a frame body.
[0079] The detailed description of step S410 can be found in step S110 and will not be repeated here.
[0080] Step S420: Determine a first data frame to be encrypted from the multiple data frames, and obtain a frame length of the first data frame to be encrypted before encoding as a first frame length.
[0081] Step S430: Determine a first traversal interval according to the first frame length, traverse the file to be encrypted according to the first traversal interval, and determine a second data frame to be encrypted from the multiple data frames.
[0082] For the detailed description of steps S420 to S430 , please refer to steps S320 to S330 , which will not be repeated here.
[0083] When the information of multiple data frames is greatly different, for example, the multiple data frames are multiple audio frames, and the timbre, pitch, speaking speed, etc. of the sound in the multiple audio frames vary greatly, the differences between the multiple audio frames are relatively large, and the data frames with large differences also have large differences in frame length before compression. Therefore, when traversing the entire file to be encrypted, it is necessary to traverse according to different traversal intervals to quickly and accurately obtain the data frames to be encrypted.
[0084] Step S440: Obtain the frame length of the second data frame to be encrypted before encoding as the second frame length.
[0085] Since the information header includes the frame length of each data frame before encoding, the frame length of the second data frame to be encrypted before encoding is obtained from the information header as the second frame length. It can be understood that the second frame length includes the sum of the length of the frame header and the frame body of the second data frame to be encrypted before encoding. Figure 4 , the file to be encrypted also includes data frame 3, wherein data frame 3 includes frame header 3 and frame body 3. Figure 4 In the example, the second frame length is the sum of the lengths of frame header 2 and frame body 2.
[0086] Step S450: Determine a second traversal interval according to the second frame length, traverse the file to be encrypted according to the second traversal interval, and determine a third data frame to be encrypted from the multiple data frames.
[0087] Similarly, first, an encoding method for encoding the data frame is obtained. For example, the encoding method may be FLAC, ASCII, etc.
[0088] Then, a second traversal interval is determined according to the encoding mode and the second frame length, and a second traversal interval corresponding to both the encoding mode and the second frame length is determined based on the preset mapping relationship among the plurality of encoding modes, the plurality of frame lengths, and the plurality of traversal intervals established in advance.
[0089] For example, when the encoding method is FLAC encoding, the preset mapping relationship between FLAC encoding, frame length and traversal interval can be expressed as follows: l = L*40%, where l is the traversal interval and L is the frame length. When L2 is the second frame length, the second traversal interval l2 is as follows: Figure 4 shown.
[0090] Then, the file to be encrypted is traversed according to the second traversal interval, and the third data frame to be encrypted is determined from the multiple data frames. Figure 4 , continue to traverse along the traversal direction, and after jumping to the second traversal interval, access the frame header 3, then the data frame 3 corresponding to the frame header 3 is used as the third data frame to be encrypted.
[0091] It should be noted that the multiple data frames are not limited to the above-mentioned data frame 1, data frame 2 and data frame 3, and can also be more data frames. The traversal interval is determined according to the frame length of the previous data frame, and traversal is performed according to the traversal interval.
[0092] Step S460: Determine the first data frame to be encrypted, the second data frame to be encrypted, and the third data frame to be encrypted as the data frames to be encrypted.
[0093] It should be noted that the number of multiple data frames is not limited to Figure 4 The data frames in the encryption scheme may also be more data frames. Therefore, the data frames to be encrypted are not limited to the first data frame to be encrypted, the second data frame to be encrypted, and the third data frame to be encrypted, and may also be more data frames.
[0094] Step S470: Obtain a frame header included in the data frame to be encrypted as a frame header to be encrypted, and encrypt the frame header to be encrypted to obtain an encrypted file.
[0095] The detailed description of step S470 can be found in step S130 and will not be repeated here.
[0096] In this embodiment, different traversal intervals are used to traverse the file to be encrypted, so that the obtained multiple data frames to be encrypted are evenly distributed in the file to be encrypted, and then the encrypted frame headers of the data frames to be encrypted are encrypted to obtain the encrypted file, thereby improving the security of the encrypted file.
[0097] Based on the above embodiments, this embodiment provides a file encryption method, which improves the security of encrypted files through encryption processing and random processing. Figure 6 A flowchart showing a file encryption method provided by another embodiment of the present application is shown. Figure 6 , the file encryption method may specifically include the following steps:
[0098] Step S510: Acquire a file to be encrypted, wherein the file to be encrypted includes multiple data frames, and each of the multiple data frames includes a frame header and a frame body.
[0099] Step S520: Determine the data frame to be encrypted from the multiple data frames.
[0100] For the detailed description of steps S510 to S520 , please refer to steps S110 to S120 , which will not be repeated here.
[0101] Step S530: Separate the data frame to be encrypted and obtain the separated frame header of the data frame to be encrypted as the frame header to be encrypted.
[0102] Separate the encrypted data frame and combine Figure 4 In the example, the separation results are as follows Figure 7 As shown, the separation processing result includes at least frame header 1, frame header 2, frame header 3, frame body 1, frame body 2 and frame body 3. And the frame header of the data frame to be encrypted is determined as the frame header to be encrypted.
[0103] In order to further improve the security of the encrypted file, it is necessary to shuffle the separated multiple frame headers and multiple frame bodies. In order to ensure that the original sequence of multiple data frames is obtained when decrypting the encrypted file, it is necessary to pre-establish a binding relationship between the frame header and frame body included in each data frame.
[0104] In one embodiment, the position information of the frame header and the frame body included in each data frame of the plurality of data frames is obtained; based on the position information, the frame header and the frame body included in each data frame are bound. Optionally, the binding relationship corresponding to each data frame can be bound to the frame header included in each data frame. Figure 8 , the binding relationship includes a first binding relationship, a second binding relationship and a third binding relationship.
[0105] In another embodiment, identification information of a frame header and a frame body included in each data frame of the plurality of data frames is obtained; and based on the identification information, the frame header and the frame body included in each data frame are bound.
[0106] Step S540: Perform shuffling processing on multiple frame headers and multiple frame bodies included in the multiple data frames, wherein the multiple frame headers include the frame header to be encrypted.
[0107] The disorder processing refers to disrupting the original arrangement order of multiple frame headers and multiple frame bodies in the file to be encrypted, and the disorder processing of multiple frame headers and multiple frame bodies included in multiple data frames can be as follows: Figure 9 shown.
[0108] Step S550: Encrypt the frame header to be encrypted after the disorder processing to obtain the encrypted file.
[0109] The preset encryption algorithm or secret key is used to encrypt the encrypted frame headers after the disordered processing. The multiple encrypted frame headers after the disordered processing can be encrypted separately, or the multiple encrypted frame headers after the disordered processing can be combined and encrypted. Optionally, the preset encryption algorithm can be, but is not limited to, SHA, HMAC, etc. The encrypted file obtained is as follows Figure 10 shown.
[0110] The encrypted file includes the frame header to be encrypted after being processed in a disordered manner, the frame headers other than the frame header to be encrypted among the multiple frame headers, and multiple frame bodies (including the frame body of the data frame to be encrypted).
[0111] When decrypting an encrypted file, the encrypted frame header to be encrypted is decrypted using the secret key to obtain the scrambled frame header to be encrypted. Based on the binding relationship, the frame header and frame body included in the same data frame are obtained to obtain multiple data frames. Based on the position information, the positions of the multiple data frames in the original file to be encrypted are restored, and the information carried in the frame body is obtained in the order from the frame header to the frame body.
[0112] Optionally, corresponding to the frame headers to be encrypted, multiple frame headers to be encrypted may be encrypted separately first, and then the multiple encrypted frame headers may be subjected to random order processing to obtain an encrypted file.
[0113] In this embodiment, the file to be encrypted is obtained through disorder processing and encryption processing, thereby improving the security of the file to be encrypted.
[0114] To implement the above method embodiment, this embodiment provides a file encryption device. Figure 11 A block diagram of a file encryption device according to an embodiment of the present application is shown. Figure 11 The file encryption device 100 includes: a file to be encrypted obtaining module 110, a frame header to be encrypted obtaining module 120 and a file encryption module 130.
[0115] The to-be-encrypted file acquisition module 110 is configured to acquire a to-be-encrypted file, wherein the to-be-encrypted file includes a plurality of data frames, each of the plurality of data frames including a frame header and a frame body;
[0116] The to-be-encrypted frame header obtaining module 120 is configured to determine a to-be-encrypted data frame from the plurality of data frames, and obtain a frame header included in the to-be-encrypted data frame as a to-be-encrypted frame header;
[0117] The file encryption module 130 is configured to encrypt the frame header to be encrypted to obtain an encrypted file.
[0118] Optionally, the to-be-encrypted file acquisition module 110 includes: a traversal submodule.
[0119] The traversal submodule is used to traverse the file to be encrypted and determine the data frame to be encrypted from the multiple data frames.
[0120] Optionally, the traversal submodule includes: a jump traversal submodule.
[0121] The jump traversal submodule is used to jump and traverse the file to be encrypted according to the traversal interval, and determine the data frame to be encrypted from the multiple data frames.
[0122] Optionally, the to-be-encrypted frame header acquisition module 120 includes: a first frame length determination submodule, a second to-be-encrypted data frame determination submodule, and a determination submodule.
[0123] a first frame length determination submodule, configured to determine a first data frame to be encrypted from the multiple data frames, and obtain a frame length of the first data frame to be encrypted before encoding as a first frame length;
[0124] a second data frame to be encrypted determining submodule, configured to determine a first traversal interval according to the first frame length, traverse the file to be encrypted according to the first traversal interval, and determine a second data frame to be encrypted from the multiple data frames;
[0125] The determination submodule is configured to determine the first data frame to be encrypted and the second data frame to be encrypted as the data frames to be encrypted.
[0126] Optionally, the determination submodule includes: a second frame length determination submodule, a third to-be-encrypted data frame determination submodule and a common determination submodule.
[0127] A second frame length determination submodule, configured to obtain a frame length of the second to-be-encrypted data frame before encoding as a second frame length;
[0128] a third data frame to be encrypted determining submodule, configured to determine a second traversal interval according to the second frame length, traverse the file to be encrypted according to the second traversal interval, and determine a third data frame to be encrypted from the multiple data frames;
[0129] The common determination submodule is configured to determine the first data frame to be encrypted, the second data frame to be encrypted, and the third data frame to be encrypted as the data frames to be encrypted.
[0130] Optionally, the first frame length determination submodule includes: an encoding mode determination submodule, a first traversal interval determination submodule, and a second to-be-encrypted data frame determination submodule.
[0131] The encoding mode determination submodule is used to obtain the encoding mode for encoding the data frame;
[0132] A first traversal interval determination submodule, configured to determine the first traversal interval according to the encoding mode and the first frame length;
[0133] The second data frame to be encrypted determining submodule is configured to traverse the file to be encrypted according to the first traversal interval and determine the second data frame to be encrypted from the multiple data frames.
[0134] Optionally, the file to be encrypted further includes an information header, the information header includes the frame length of each data frame before encoding, and the first frame length determination submodule includes: a first frame length acquisition submodule.
[0135] The first frame length acquisition submodule is used to obtain the frame length of the first data frame to be encrypted before encoding from the information header as the first frame length.
[0136] Optionally, the to-be-encrypted frame header acquisition module 120 includes: a to-be-encrypted data frame determination submodule and a separation submodule.
[0137] a data frame to be encrypted determining submodule, configured to determine the data frame to be encrypted from the multiple data frames;
[0138] The separation submodule is configured to perform separation processing on the data frame to be encrypted, and obtain the separated frame header of the data frame to be encrypted as the frame header to be encrypted.
[0139] Optionally, a frame header and a frame body included in each data frame are in a binding relationship, and the file encryption module 130 includes: a random submodule and an encryption submodule.
[0140] a shuffling submodule, configured to shuffle a plurality of frame headers and a plurality of frame bodies included in the plurality of data frames, wherein the plurality of frame headers include the frame header to be encrypted;
[0141] The encryption submodule is used to encrypt the frame header to be encrypted after the disorder processing to obtain the encrypted file.
[0142] Optionally, the file encryption device 100 further includes: a location information acquisition module and a binding module.
[0143] a position information acquisition module, configured to acquire position information of a frame header and a frame body included in each of the plurality of data frames;
[0144] A binding module is used to bind the frame header and frame body included in each data frame based on the location information.
[0145] Optionally, the data frame to be encrypted is part or all of the multiple data frames.
[0146] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0147] In several embodiments provided in this application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0148] In addition, the functional modules in the various embodiments of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into a single module. The above-mentioned integrated modules may be implemented in the form of hardware or software functional modules.
[0149] Figure 12 This is a block diagram of an electronic device for executing the file encryption method according to an embodiment of the present application. Figure 12 , which shows a structural block diagram of an electronic device 200 provided in an embodiment of the present application. The electronic device 200 can be an electronic device capable of running applications, such as a smartphone, a tablet computer, an e-book, etc. The electronic device 200 in the present application may include one or more of the following components: a processor 210, a memory 220, and one or more applications, wherein the one or more applications may be stored in the memory 220 and configured to be executed by one or more processors 210, and the one or more programs are configured to execute the method described in the aforementioned method embodiment.
[0150] The processor 210 may include one or more processing cores. The processor 210 utilizes various interfaces and circuits to connect various components within the electronic device 200. It executes instructions, programs, code sets, or instruction sets stored in the memory 220, and accesses data stored in the memory 220 to perform various functions and process data within the electronic device 200. Optionally, the processor 210 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 310 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing components to be displayed; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 210 and may be implemented separately via a communication chip.
[0151] The memory 220 may include a random access memory (RAM) or a read-only memory (ROM). The memory 220 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 220 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a historical configuration file) created by the electronic device 200 during use.
[0152] Figure 13 A storage unit for storing or carrying program code for implementing the file encryption method according to an embodiment of the present application is shown. See 13 , which shows a block diagram of a computer-readable storage medium provided by an embodiment of the present application. The computer-readable medium 300 stores program code that can be invoked by a processor to execute the method described in the above method embodiment.
[0153] The computer-readable storage medium 300 may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer-readable storage medium 400 may include a non-transitory computer-readable storage medium. The computer-readable storage medium 300 may have storage space for program code 310 for executing any of the method steps described above. These program codes may be read from or written to one or more computer program products. The program code 310 may be compressed, for example, in a suitable form.
[0154] In the file encryption method, device, electronic device and storage medium provided in this embodiment, a file to be encrypted is obtained, and the file to be encrypted includes multiple data frames, each of the multiple data frames includes a frame header and a frame body, and then the data frame to be encrypted is determined from the multiple data frames, and the frame header included in the data frame to be encrypted is obtained as the frame header to be encrypted, the frame header to be encrypted is encrypted to obtain an encrypted file, the frame header to be encrypted is encrypted, and the frame body is not encrypted, which can achieve fast encryption and make the data volume of the encrypted file smaller, which can save network transmission resources and storage resources.
[0155] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A file encryption method, characterized in that: include: Acquire a file to be encrypted, and determine the encryption level of the file to be encrypted, wherein the file to be encrypted includes a plurality of data frames, each of the plurality of data frames includes a frame header and a frame body; each data frame in the file to be encrypted is an encoded data frame; Determining the number of data frames to be encrypted according to the encryption level; Obtaining a traversal interval according to the frame length of the data frame before encoding and the encoding method of the file to be encrypted; According to the traversal interval, jump and traverse the file to be encrypted to obtain the number of data frames to be encrypted; Encrypting the frame header of each data frame to be encrypted to obtain an encrypted file; The number of data frames to be encrypted includes the first data frame to be encrypted and other data frames to be encrypted that are located after the first data frame to be encrypted; the first data frame to be encrypted is the first data frame to be encrypted that is traversed and determined in the file to be encrypted along the traversal direction; the traversal direction is the direction from the information header in the file to be encrypted to the data frame in the file to be encrypted; The step of obtaining a traversal interval according to a frame length of the data frame before encoding and an encoding method of the file to be encrypted; and jumping and traversing the file to be encrypted according to the traversal interval to obtain the number of data frames to be encrypted includes: Obtaining a frame length of the i-th data frame to be encrypted before encoding, wherein i is a positive integer and i does not exceed the number, and when i=1, the i-th data frame to be encrypted is the first data frame to be encrypted; According to the correspondence between the traversal interval, the encoding mode and the frame length, determine the traversal interval corresponding to the encoding mode of the file to be encrypted and the frame length of the i-th data frame to be encrypted before encoding as the i-th traversal interval; According to the i-th traversal interval, traverse the data frames after the i-th data frame to be encrypted in the file to be encrypted along the traversal direction to determine the i+1-th data frame to be encrypted; the interval between the frame header of the i+1-th data frame to be encrypted and the frame header of the i-th data frame to be encrypted is equal to the i-th traversal interval; If i+1 is less than the number, i is cumulatively increased by 1, and the process returns to execute the step of obtaining the frame length of the i-th data frame to be encrypted before encoding; or, The traversal interval includes a first traversal interval, and the traversal interval is obtained according to the frame length of the data frame before encoding and the encoding method of the file to be encrypted; and according to the traversal interval, the file to be encrypted is jumped and traversed to obtain the number of data frames to be encrypted, including: obtaining the frame length of the first data frame to be encrypted before encoding; According to the correspondence between the traversal interval, the encoding mode and the frame length, determining a traversal interval corresponding to the encoding mode of the to-be-encrypted file and the frame length of the first to-be-encrypted data frame before encoding as a first traversal interval; According to the first traversal interval, the data frames following the first data frame to be encrypted in the file to be encrypted are traversed along the traversal direction to determine other data frames to be encrypted located after the first data frame to be encrypted; wherein the traversal interval between two adjacent data frames to be encrypted in the file to be encrypted is equal to the first traversal interval.
2. The method according to claim 1, characterized in that: The information header includes the frame length of each data frame before encoding; the obtaining the frame length of the i-th data frame to be encrypted before encoding includes: The frame length of the i-th data frame to be encrypted before encoding is obtained from the information header.
3. The method according to claim 1, characterized in that Before encrypting the frame header of each of the data frames to be encrypted to obtain the encrypted file, the method further includes: Separate and process each of the data frames to be encrypted to determine the frame header and frame body from each of the data frames to be encrypted.
4. The method according to claim 3, characterized in that The frame header and the frame body included in each data frame are in a binding relationship, and the encrypting the frame header of each data frame to be encrypted to obtain an encrypted file includes: Encrypting the frame header of each data frame to be encrypted, and performing random processing on the encrypted frame header, the unencrypted frame header, and all frame bodies to obtain the encrypted file; or After all frame headers and all frame bodies are processed in disorder, the frame header of the data frame to be encrypted is encrypted to obtain the encrypted file.
5. The method according to claim 4, characterized in that Before encrypting the frame header of each of the data frames to be encrypted to obtain the encrypted file, the method further includes: Acquire position information of a frame header and a frame body included in each of the multiple data frames; Based on the location information, a frame header and a frame body included in each data frame are bound.
6. The method according to claim 5, characterized in that After binding the frame header and frame body included in each data frame based on the location information, the method further includes: After binding the frame header and frame body included in each data frame to obtain the binding relationship corresponding to each data frame, the binding relationship corresponding to each data frame is bound to the frame header in the corresponding data frame.
7. A file encryption device, characterized in that: The device comprises: The module for acquiring a file to be encrypted is used to acquire a file to be encrypted and determine the encryption level of the file to be encrypted, wherein the file to be encrypted includes a plurality of data frames, each of the plurality of data frames includes a frame header and a frame body; according to the encryption level, the number of the data frames to be encrypted is determined; each data frame in the file to be encrypted is an encoded data frame; The module for obtaining the frame header to be encrypted is used to obtain the traversal interval according to the frame length of the data frame before encoding and the encoding method of the file to be encrypted; according to the traversal interval, jump and traverse the file to be encrypted to obtain the number of data frames to be encrypted; A file encryption module, used for encrypting the frame header of each data frame to be encrypted to obtain an encrypted file; The number of data frames to be encrypted includes the first data frame to be encrypted and other data frames to be encrypted that are located after the first data frame to be encrypted; the first data frame to be encrypted is the first data frame to be encrypted that is traversed and determined in the file to be encrypted along the traversal direction; the traversal direction is the direction from the information header in the file to be encrypted to the data frame in the file to be encrypted; The module for obtaining the frame header to be encrypted is used to: obtain the frame length of the i-th data frame to be encrypted before encoding, wherein i is a positive integer and i does not exceed the number. When i=1, the i-th data frame to be encrypted is the first data frame to be encrypted; according to the correspondence between the traversal interval, the encoding mode and the frame length, determine the traversal interval corresponding to the encoding mode of the file to be encrypted and the frame length of the i-th data frame to be encrypted before encoding as the i-th traversal interval; according to the i-th traversal interval, traverse the data frames after the i-th data frame to be encrypted in the file to be encrypted along the traversal direction to determine the i+1-th data frame to be encrypted; the interval between the frame header of the i+1-th data frame to be encrypted and the frame header of the i-th data frame to be encrypted is equal to the i-th traversal interval; if i+1 is less than the number, add 1 to i cumulatively, and return to execute the step of obtaining the frame length of the i-th data frame to be encrypted before encoding; Alternatively, the traversal interval includes a first traversal interval, and the module for obtaining the frame header to be encrypted is used to: obtain the frame length of the first data frame to be encrypted before encoding; determine, according to the correspondence between the traversal interval, the encoding method and the frame length, the traversal interval corresponding to the encoding method of the file to be encrypted and the frame length of the first data frame to be encrypted before encoding as the first traversal interval; according to the first traversal interval, traverse the data frames after the first data frame to be encrypted in the file to be encrypted along the traversal direction to determine other data frames to be encrypted located after the first data frame to be encrypted; wherein the traversal interval between two adjacent data frames to be encrypted in the file to be encrypted is equal to the first traversal interval.
8. An electronic device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program, and the program can be called by a processor to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for encrypting and publishing video file
CN109600631A
Video and audio credible playing method based on asymmetric encryption
CN110602570A
Data communication method and related device
CN111132229A