CN-117149721-B - File processing method, device, storage medium and computer equipment
Abstract
The application discloses a file processing method, a device, a storage medium and computer equipment, wherein the method is applied to the computer equipment and comprises the steps of obtaining an original file to be transmitted, carrying out byte processing on the original file to obtain a byte array, respectively storing data in the byte array into a canvas according to a channel storage mode, a two-channel storage mode and a three-channel storage mode, compressing the data by a compression mode supported by the canvas to obtain compressed one-channel data, two-channel data and three-channel data, taking the data with the smallest data quantity in the one-channel data, the two-channel data, the three-channel data and the byte array as data to be encrypted corresponding to the byte array, carrying out encryption processing on the data to be encrypted to obtain the encrypted data of the original file, and balancing the compression and encryption to a certain extent.
Inventors
- CHEN BING
Assignees
- 深圳TCL新技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20221024
Claims (19)
- 1. A document processing method, comprising: Acquiring an original file to be transmitted; the original file is byte-formed to obtain a byte array; Splitting the data in the byte array according to the maximum filling text data supported by the canvas to obtain at least one single byte array; For each single byte array in at least one single byte array, determining a target storage channel to be stored of each single byte array according to a channel storage mode, a two-channel storage mode and a three-channel storage mode, wherein the target storage channel corresponding to the one-channel storage mode is any one channel of an R channel, a G channel and a B channel, the target storage channel corresponding to the two-channel storage mode is any two channels of the R channel, the G channel and the B channel, and the target storage channel corresponding to the three-channel storage mode is the R channel, the G channel and the B channel; writing the target storage channel into an identification code of each single byte array, and filling the identification code into a first pixel of the canvas; Sequentially storing the data in each single byte array into the target storage channels corresponding to other pixels of the canvas; compressing in a compression mode supported by the canvas to obtain one-channel data, two-channel data and three-channel data of each single byte array after compression, wherein the canvas is used for displaying a plurality of pixels; The one-channel data, the two-channel data, the three-channel data and the data with the smallest data quantity in each single byte array are taken as the data to be encrypted corresponding to each single byte array in the byte arrays after the compression of each single byte array; and encrypting the data to be encrypted corresponding to each single byte array in the byte arrays to obtain the encrypted data corresponding to each single byte array of the original file.
- 2. The method of claim 1, wherein the step of splitting the data in the byte array to obtain at least one monolithic byte array based on the maximum fill text data supported by the canvas comprises: Determining the number of blocks to be split according to the maximum filling text data supported by the canvas and the size of the byte array, wherein the maximum filling text data supported by the canvas is at least related to displacement multiples; And splitting the data in the byte array according to the blocking quantity to obtain at least one single byte array.
- 3. The method of claim 1, wherein the step of encrypting the data to be encrypted corresponding to each of the single-block byte arrays of the byte arrays to obtain the encrypted data corresponding to each of the single-block byte arrays of the original file comprises: acquiring a key array, a position transformation array and a displacement multiple for encryption, wherein the position transformation array is obtained by sequencing the key array; And according to the key array, the position transformation array and the displacement multiple, encrypting the data to be encrypted corresponding to each single byte array in the byte arrays to obtain the encrypted data corresponding to each single byte array of the original file.
- 4. The method of claim 3, wherein the step of encrypting the data to be encrypted corresponding to each of the byte arrays according to the key array, the position transformation array, and the displacement multiple to obtain the encrypted data corresponding to each of the byte arrays of the original file comprises: For the data to be encrypted corresponding to each single byte array in the byte arrays, corresponding the value of each data in the key array to the corresponding row or the corresponding column of the data to be encrypted according to the displacement multiple; determining position information of a value of each datum in the position transformation array, and determining a target row or a target column according to the position information and the displacement multiple; and exchanging the data of the corresponding row or the corresponding column of the data to be encrypted with the data of the target row or the target column to obtain the encrypted data corresponding to the single byte array.
- 5. A method according to claim 3, wherein the step of obtaining a multiple of the displacement comprises: Acquiring the size of the original file, the maximum number of bytes supported by the canvas and the determined maximum number of blocks; Determining the corresponding maximum processing file size under a multiple according to the size, the maximum byte number and the maximum block number; and determining displacement multiples according to the size of the original file and the size of the maximum processing file.
- 6. A method according to claim 3, wherein obtaining the key array and the location transform array comprises: obtaining an encryption key plaintext, and encrypting the encryption key plaintext by using a preset encryption algorithm to obtain a key ciphertext; Converting the key ciphertext into a byte array to obtain a key array; and sequencing the data in the key array according to a preset sequence, and taking the array which stores the position of each data in the key array after sequencing as a position conversion array.
- 7. The method of claim 1, wherein after obtaining the data to be encrypted for each of the byte arrays, the method further comprises: for the data to be encrypted, determining the byte number of blank filling data to be filled and the blank filling data to be filled; and filling the blank filling data with the byte number of the blank filling data behind the data to be encrypted so as to obtain the filled data to be encrypted.
- 8. The method of claim 7, wherein the step of determining the number of bytes of blank pad data to be padded for the data to be encrypted comprises: determining the fixed line number of the canvas according to the displacement multiple; determining the minimum width of the canvas according to the data to be encrypted and the fixed line number; and determining the byte number of blank filling data to be filled according to the minimum width of the canvas, the displacement multiple and the data to be encrypted.
- 9. The method according to claim 1, wherein the method further comprises: Writing the file type to an identification code of each of the at least one monolithic byte array, and/or, After splitting the data in the byte array, the method further comprises: the split block number is written to an identification code of each of the at least one monolithic byte array.
- 10. The method according to any one of claims 1-9, further comprising, after obtaining the encrypted data corresponding to each monolithic byte array of the original file: And exporting and transmitting the encrypted data in the form of pictures, or writing the encrypted data into a text file and transmitting the encrypted data.
- 11. A document processing method, comprising: acquiring encrypted data of an original file; decrypting the encrypted data to obtain decrypted data of the original file; if the decrypted data is compressed, writing the decrypted data into a canvas for decompression so as to obtain a byte array corresponding to the decrypted data; converting the byte array according to the file type to obtain the original file; The encrypted data is obtained by the following steps: the original file is byte-formed to obtain a byte array; Splitting the data in the byte array according to the maximum filling text data supported by the canvas to obtain at least one single byte array; For each single byte array in at least one single byte array, determining a target storage channel to be stored of each single byte array according to a channel storage mode, a two-channel storage mode and a three-channel storage mode, wherein the target storage channel corresponding to the one-channel storage mode is any one channel of an R channel, a G channel and a B channel, the target storage channel corresponding to the two-channel storage mode is any two channels of the R channel, the G channel and the B channel, and the target storage channel corresponding to the three-channel storage mode is the R channel, the G channel and the B channel; writing the target storage channel into an identification code of each single byte array, and filling the identification code into a first pixel of the canvas; Sequentially storing the data in each single byte array into the target storage channels corresponding to other pixels of the canvas; compressing in a compression mode supported by the canvas to obtain one-channel data, two-channel data and three-channel data of each single byte array after compression, wherein the canvas is used for displaying a plurality of pixels; The one-channel data, the two-channel data, the three-channel data and the data with the smallest data quantity in each single byte array are taken as the data to be encrypted corresponding to each single byte array in the byte arrays after the compression of each single byte array; and encrypting the data to be encrypted corresponding to each single byte array in the byte arrays to obtain the encrypted data corresponding to each single byte array of the original file.
- 12. The method of claim 11, wherein the method further comprises: acquiring at least one block of encrypted data corresponding to an original file; decrypting each block of encrypted data in the at least one block of encrypted data to obtain each block of decrypted data; If the decrypted data of the corresponding block is compressed, writing the decrypted data of the corresponding block into the canvas for decompression to obtain a single byte array corresponding to the decrypted data of the corresponding block; If the decrypted data of the corresponding block exists, determining a corresponding single byte array directly according to the decrypted data of the corresponding block; Splicing each single byte array according to the sequence to obtain a byte array; And converting the byte array according to the file type to obtain the original file.
- 13. The method of claim 12, wherein the step of writing the decrypted data of the corresponding block into the canvas for decompression to obtain the monolithic byte array corresponding to the decrypted data of the corresponding block comprises: Writing the decrypted data of the corresponding block into the canvas for decompression to obtain initial restored data corresponding to the decrypted data of the corresponding block; removing the identification code and/or blank filling data in the initial restored data; And acquiring a target storage channel of the initial restored data from the identification code, and extracting data in the target storage channel from the canvas to obtain a single byte array corresponding to the decrypted data of the corresponding block.
- 14. The method of claim 12, wherein decrypting each block of encrypted data in the at least one block of encrypted data to obtain each block of decrypted data comprises: obtaining a displacement multiple, an inverted key array, and an inverted position transform array, wherein the inverted position transform array is determined from the inverted key array; and decrypting each piece of encrypted data in at least one piece of encrypted data according to the displacement multiple, the reverse key array and the reverse position transformation array to obtain each piece of decrypted data.
- 15. The method of claim 14, wherein the step of obtaining an array of reverse keys and an array of reverse position transformations comprises: obtaining an encryption key plaintext, and encrypting the encryption key plaintext by using a preset encryption algorithm to obtain a key ciphertext; Converting the key ciphertext into a byte array to obtain a key array; The data in the key array are ordered according to a preset sequence, and an array which stores the position of each data in the key array after the ordering is used as a position transformation array; and carrying out inversion processing on the data in the key array and the position transformation array to obtain an inverted key array and an inverted position transformation array respectively.
- 16. A document processing apparatus, comprising: The first acquisition module is used for acquiring an original file to be transmitted; The byte module is used for byte the original file to obtain a byte array; The compression module is used for splitting the data in the byte array according to the maximum filling text data supported by the canvas so as to obtain at least one single byte array; For each single byte array in at least one single byte array, determining a target storage channel to be stored of each single byte array according to a channel storage mode, a two-channel storage mode and a three-channel storage mode, wherein the target storage channel corresponding to the one-channel storage mode is any one channel of an R channel, a G channel and a B channel, the target storage channel corresponding to the two-channel storage mode is any two channels of the R channel, the G channel and the B channel, and the target storage channel corresponding to the three-channel storage mode is the R channel, the G channel and the B channel; writing the target storage channel into an identification code of each single byte array, and filling the identification code into a first pixel of the canvas; Sequentially storing the data in each single byte array into the target storage channels corresponding to other pixels of the canvas; compressing in a compression mode supported by the canvas to obtain one-channel data, two-channel data and three-channel data of each single byte array after compression, wherein the canvas is used for displaying a plurality of pixels; the data determining module is used for taking the one-channel data, the two-channel data, the three-channel data and the data with the smallest data quantity in each single byte array after the compression of each single byte array in the byte arrays as the data to be encrypted corresponding to each single byte array in the byte arrays; and the encryption module is used for carrying out encryption processing on the data to be encrypted corresponding to each single byte array in the byte arrays so as to obtain the encrypted data corresponding to each single byte array of the original file.
- 17. A document processing apparatus, comprising: the second acquisition module is used for acquiring the encrypted data of the original file; the decryption module is used for decrypting the encrypted data to obtain decrypted data of the original file; the decompression module is used for writing the decrypted data into the canvas for decompression if the decrypted data is compressed so as to obtain a byte array corresponding to the decrypted data; The conversion module is used for converting the byte array according to the file type to obtain the original file; The encrypted data is obtained by the following steps: the original file is byte-formed to obtain a byte array; Splitting the data in the byte array according to the maximum filling text data supported by the canvas to obtain at least one single byte array; For each single byte array in at least one single byte array, determining a target storage channel to be stored of each single byte array according to a channel storage mode, a two-channel storage mode and a three-channel storage mode, wherein the target storage channel corresponding to the one-channel storage mode is any one channel of an R channel, a G channel and a B channel, the target storage channel corresponding to the two-channel storage mode is any two channels of the R channel, the G channel and the B channel, and the target storage channel corresponding to the three-channel storage mode is the R channel, the G channel and the B channel; writing the target storage channel into an identification code of each single byte array, and filling the identification code into a first pixel of the canvas; Sequentially storing the data in each single byte array into the target storage channels corresponding to other pixels of the canvas; compressing in a compression mode supported by the canvas to obtain one-channel data, two-channel data and three-channel data of each single byte array after compression, wherein the canvas is used for displaying a plurality of pixels; The one-channel data, the two-channel data, the three-channel data and the data with the smallest data quantity in each single byte array are taken as the data to be encrypted corresponding to each single byte array in the byte arrays after the compression of each single byte array; and encrypting the data to be encrypted corresponding to each single byte array in the byte arrays to obtain the encrypted data corresponding to each single byte array of the original file.
- 18. A computer readable storage medium having stored therein a plurality of instructions adapted to be loaded by a processor to perform the steps in the file processing method of any of claims 1 to 15.
- 19. A computer device comprising a processor and a memory, the processor being electrically connected to the memory, the memory being for storing instructions and data, the processor being for performing the steps of the file processing method of any of claims 1 to 15.
Description
File processing method, device, storage medium and computer equipment Technical Field The present application relates to the field of data processing technologies, and in particular, to a method and apparatus for processing a file, a storage medium, and a computer device. Background With the development of technology, users have increasingly higher demands on confidentiality and speed of data in transmission. For example, in some application scenarios where data is sensitive but the network environment is not good and is not secure, when private data needs to be transmitted or files need to be uploaded and downloaded, the problem that the private data or the file content is hijacked in the transmission process or the server database is attacked to cause the file content to be leaked may occur, so that in order to optimize the problem of long transmission and reduce the bandwidth occupation, compression processing is generally required to be performed on the data or the files, and in order to prevent the data or the files from being leaked, encryption processing may be generally performed on the data or the files. Whereas compression is a process of reducing information entropy, encryption is a process of increasing information entropy, and if the degree of increase of information entropy exceeds the degree of decrease of information entropy, compression is not meaningful. Disclosure of Invention The embodiment of the application provides a file processing method, a file processing device, a storage medium and computer equipment, which can achieve the balance of compression and encryption to a certain extent. The embodiment of the application provides a file processing method, which comprises the following steps: Acquiring an original file to be transmitted; the original file is byte-formed to obtain a byte array; storing the data in the byte array into a canvas according to a one-channel storage mode, a two-channel storage mode and a three-channel storage mode respectively, and compressing the data by a compression mode supported by the canvas to obtain compressed one-channel data, two-channel data and three-channel data, wherein the canvas is used for displaying a plurality of pixels; taking the data with the smallest data quantity in the one-channel data, the two-channel data, the three-channel data and the byte array as the data to be encrypted corresponding to the byte array; And carrying out encryption processing on the data to be encrypted to obtain the encrypted data of the original file. The embodiment of the application also provides a file processing method, which comprises the following steps: Obtaining encrypted data of an original file, wherein the encrypted data is obtained by byte-forming the original file to obtain a byte array, respectively storing data in the byte array into a canvas according to a one-channel storage mode, a two-channel storage mode and a three-channel storage mode, compressing the data by a compression mode supported by the canvas to obtain compressed one-channel data, two-channel data and three-channel data, and encrypting the data to be encrypted, which correspond to the byte array, by taking the data with the minimum data quantity in the one-channel data, the two-channel data, the three-channel data and the byte array as the data to be encrypted; decrypting the encrypted data to obtain decrypted data of the original file; if the decrypted data is compressed, writing the decrypted data into a canvas for decompression so as to obtain a byte array corresponding to the decrypted data; And converting the byte array according to the file type to obtain the original file. The embodiment of the application also provides a file processing device, which comprises: The first acquisition module is used for acquiring an original file to be transmitted; The byte module is used for byte the original file to obtain a byte array; The compression module is used for respectively storing the data in the byte array into a canvas according to a one-channel storage mode, a two-channel storage mode and a three-channel storage mode, compressing the data by a compression mode supported by the canvas to obtain compressed one-channel data, two-channel data and three-channel data, and the canvas is used for displaying a plurality of pixels; The data determining module is used for taking the data with the smallest data quantity in the one-channel data, the two-channel data, the three-channel data and the byte array as the data to be encrypted corresponding to the byte array; and the encryption module is used for carrying out encryption processing on the data to be encrypted so as to obtain the encrypted data of the original file. The embodiment of the application also provides a file processing device, which comprises: The second acquisition module is used for acquiring the encrypted data of the original file, wherein the encrypted data is obtained by byte-forming the original file, storing the da