Large file and QR code conversion and restoration method, device and storage medium

By using Aztec codes and partial encryption processing determined by file density thresholds, the problems of low efficiency and insufficient security in large file QR code transmission are solved, achieving more efficient and secure file transmission.

CN118394724BActive Publication Date: 2024-08-30BEIJING XINYAN HUIZHI INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410790179.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-08-30
Estimated Expiration
2044-06-19

AI Technical Summary

Technical Problem

The existing technology has low efficiency and insufficient security when large files are transmitted through QR codes. Frequent splitting and scanning are required, and the QR code generation and processing programs are stored on the user's computer, which poses a risk of being stolen.

Method used

Aztec code is used to replace QR-Code, and the file density threshold is used to determine whether to encrypt file blocks, and partial encryption is performed in the QR code conversion device to generate and store QR codes to ensure the security and efficiency of file transmission.

Benefits of technology

It reduces the number of QR codes, improves transmission efficiency, ensures file security through partial encryption, prevents file theft, and improves overall security and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118394724B
    Figure CN118394724B
Patent Text Reader

Abstract

The present invention relates to a conversion and restoration method, device and storage medium for large files and two-dimensional codes. The method compresses and decomposes the original file into file blocks, calculates the file density of the file blocks, and selects whether to encrypt according to the file density. The two-dimensional code conversion device converts the file description information, the file body content and the encrypted description information into corresponding Aztec codes and outputs them to a display system. The two-dimensional code conversion device combines the data of the two-dimensional code and restores it to a copy of the source file. The present invention adopts a partial two-dimensional code encryption method that encrypts part of the file blocks after decomposing the compressed file into blocks and then converts the file blocks into two-dimensional codes one by one. This method has less storage space than overall encryption; and if the thief steals all the two-dimensional code graphics, the single part of the data cannot be decrypted and cannot be restored to a normal decompressible file, thus ensuring that the source file will not be stolen, and the security is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method, device and storage medium for converting and restoring a large file and a two-dimensional code, and belongs to the technical field of electronic information. Background Art

[0002] The storage capacity of a single QR code is limited. If a large file needs to be transmitted via a QR code, it is necessary to split the large file (a file ≥100MB is defined as a large file) into several small pieces. The size of each small piece can just fit into the storage space of a QR code. This is the only way to conveniently transmit the large file via QR code scanning.

[0003] The receiving end of the QR code information needs to merge the data contents of several received QR code graphics and then restore them into a copy of the original file.

[0004] In this way, there are two key issues involved in the process of file transfer:

[0005] 1. Efficiency issue. For files of the same size, the fewer QR code graphics are split, the better the efficiency. This is because the number of QR code display and scanning times will be significantly reduced. In the process of QR code graphic transmission, the main bottleneck lies in the display and scanning process of the QR code. Even industrial-grade scanning equipment can scan no more than 100 QR codes per second.

[0006] 2. Security issues: During the data transmission process via QR code, if the QR code is scanned by a third party, the file will be leaked.

[0007] For example, existing technical solutions are generally deployed on the user's operating system through a conversion program. The program performs the following operations:

[0008] QR code generation

[0009] 1) Compress the original file using a compression algorithm;

[0010] 2) Convert the compressed file to base64;

[0011] 3) Split the transcoded base64 data;

[0012] 4) Convert the split base64 data into QR-Code one by one.

[0013] 5) Store and display QR codes;

[0014] Restoration of files;

[0015] 1) Splice the scanned information;

[0016] 2) Restore the base64 data to the binary stream of the compressed file;

[0017] 3) Unzip the file to get a copy of the original file.

[0018] The disadvantages of this technique are:

[0019] 1. Compressing the file can effectively reduce the size of the original file, but after base64 transcoding, its size will increase by at least one third. At the same time, the storage limit of QR-Code itself is 2953 bytes, so every 100MB of base64 encoded data will generate 35508 QR code graphics, which is a large number and low conversion efficiency.

[0020] 2. For the above QR code generation and restoration process, the program is stored on the user's computer. If the user's computer is illegally hacked, the QR code generation algorithm logic will be stolen. At the same time, the QR code generation process does not encrypt the data, so there is also a risk of unauthorized scanning.

[0021] Based on this, the present invention is proposed. Summary of the invention

[0022] In view of the shortcomings of the prior art, the present invention provides a method, device and storage medium for converting and restoring large files and two-dimensional codes. The specific technical scheme is as follows:

[0023] To achieve the above object, in a first aspect, the present invention provides a method for converting and restoring a large file to a two-dimensional code, comprising the following steps:

[0024] Step S1: Conversion between large files and QR codes

[0025] Step S1.1, transferring the original file to a QR code conversion device;

[0026] Step S1.2, the two-dimensional code conversion device compresses the original file using a compression algorithm to obtain a compressed file; decomposes the compressed file into blocks to obtain file blocks; calculates the file density of each file block;

[0027] When the file density of the file block is greater than a predetermined threshold, the file block is encrypted;

[0028] When the file density of the file block is less than a predetermined threshold, the file block is not encrypted;

[0029] Step S1.3, the two-dimensional code conversion device generates the first n1 groups of data packets, i.e., file description information, according to the file name, file size, and file hash value; the two-dimensional code conversion device converts the first n1 groups of data packets into the first Aztec code and outputs them to the display system, where n1 is a positive integer;

[0030] Step S1.4, the two-dimensional code conversion device disassembles the compressed file, and generates n2 intermediate data packets, i.e., the file body content, through all the file blocks that have been partially encrypted; the two-dimensional code conversion device converts the n2 intermediate data packets into the second Aztec code and outputs them to the display system, where n2 is a positive integer;

[0031] Step S1.5, the two-dimensional code conversion device generates an array with the number information of the encrypted file block, and converts it into the next n3 groups of data packets, i.e., the encrypted description information; the two-dimensional code conversion device converts the next n3 groups of data packets into the third Aztec code and outputs it to the display system, where n3 is a positive integer;

[0032] Step S2: Combine the QR code data through the QR code conversion device and restore it into a copy of the source file

[0033] Step S2.1, the two-dimensional code conversion device verifies whether all data packets have arrived completely and each data packet has passed the verification;

[0034] Step S2.2, the two-dimensional code conversion device finds the encrypted file block in the received file body content according to the data packet in the array corresponding to the number information of the encrypted file block in the received encrypted description information, and decrypts it;

[0035] Step S2.3, the QR code conversion device reassembles all the unencrypted file blocks and decrypted file blocks in the received file body content into a complete file in order;

[0036] Step S2.4, the QR code conversion device verifies the integrity of the file again according to the file hash value and file size described in the first n1 groups of data packets about the file name, file size, and file hash in the received file description information;

[0037] Step S2.5, the QR code conversion device decompresses the text content of the file to obtain a copy of the original file;

[0038] Step S2.6, the QR code conversion device saves the decompressed content as a temporary file name;

[0039] Step S2.7, the QR code conversion device uses the file name in the file description information to rename the temporary file name to the file name of the source file;

[0040] Step S2.8: The two-dimensional code conversion device transmits a copy of the original file to the destination file device.

[0041] As a further improvement, in step S1.2, the binary content of the compressed file is disassembled according to the set data packet structure. The set data packet structure includes a packet header and a packet body. The packet header includes the file name, serial number, total number of blocks, packet type, checksum and reserved area, and the packet body is the file content.

[0042] As a further improvement, the file hash value is calculated using the national encryption SM3 algorithm.

[0043] As a further improvement, the method for partially encrypting a compressed file includes the following steps:

[0044] 1) Using the least squares method, a linear regression function is fitted to the file density of the file blocks obtained after the compressed file is disassembled;

[0045] 2) Calculate the sampling position. The random sampling position p is:

[0046] ,

[0047] F is the total size of the file block, i represents the index of the slice, N represents the number of slices, S is the size of each slice, and rnd function is a random sampling function;

[0048] 3) Name the fitted function as df function, set the density factor as d, the file position (i.e. the random sampling position) as p, and the total size of the file block as F, then the density factor d is:

[0049] ,

[0050] 4) According to the random sampling position, the value of the density factor d of each sampling position is obtained; a threshold k is set, when the value of the density factor d is greater than k, the sampling is retained; when the value of the density factor d is less than or equal to k, the sampling is discarded;

[0051] 5) According to the sampled data that meets the conditions, the encrypted data is calculated and the original data is replaced to obtain the encrypted file block.

[0052] As a further improvement, in step S1.2, the original file is compressed using a zip compression method.

[0053] In the second aspect, a device for converting and restoring large files and two-dimensional codes includes a memory and a processor. The memory stores a computer program, and the processor implements the steps of the method for converting and restoring large files and two-dimensional codes when calling the computer program in the memory.

[0054] In a third aspect, a storage medium (which is a computer-readable storage medium) stores a computer program, which, when executed by a processor, implements the steps of the method for converting and restoring the large file into a two-dimensional code.

[0055] Beneficial effects of the present invention:

[0056] 1. The core of the present invention is the unique file disassembly / segmentation scheme and the operation of disassembling the file into a QR code and restoring the file into a QR code by an independent QR code conversion device.

[0057] 2. Due to the use of Aztec codes with larger storage space, the number of QR codes generated is less than that of QR codes. At the same time, in the QR code, binary two-bit strings are directly stored, which will not cause the storage space to be larger and cleared. In addition, the partial QR code encryption method of decomposing the compressed file into blocks, encrypting some file blocks, and then converting the file blocks one by one into QR codes uses less storage space than the overall encryption method.

[0058] 3. The present invention uses partial encryption to encrypt data. If the file thief steals the entire QR code graphic, the single part of the data cannot be decrypted, nor can it be restored to a normal decompressed file, thus ensuring that the source file (the original file or a copy of the original file) will not be stolen, and the security is high. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 It is a connection diagram of the QR code conversion device, source file device and display system at the data source end;

[0060] Figure 2 This is a connection diagram of the QR code conversion device, code scanning device, and destination file device at the data destination end. DETAILED DESCRIPTION

[0061] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0062] Definitions of Abbreviations and Key Terms

[0063] Base64: It is one of the most common encoding methods for transmitting 8-byte codes on the Internet. Base64 is a method of representing binary data based on 64 printable characters.

[0064] QR-Code: The abbreviation of Quick Response Code, which is a matrix barcode or two-dimensional barcode encoding method; it can also be referred to as QR code;

[0065] Aztec: is a scannable matrix barcode that is encoded to store a specific set of data;

[0066] zip: is a file format for data compression and document storage;

[0067] JSON (JavaScript Object Notation) is a lightweight data exchange format;

[0068] National Secret SM3 Algorithm: It is a cryptographic hash function standard, and the relevant standard is "GM / T 0004-2012 "SM3 Cryptographic Hash Algorithm"". Example 1

[0069] The method for converting and restoring a large file to a QR code includes the following steps:

[0070] Step S1: Conversion between large files and QR codes

[0071] Step S1.1, transferring the original file (the original file is a large file) to a QR code conversion device;

[0072] Step S1.2, the two-dimensional code conversion device compresses the original file using a compression algorithm to obtain a compressed file; decomposes the compressed file into blocks to obtain file blocks; calculates the file density of each file block;

[0073] When the file density of the file block is greater than a predetermined threshold, the file block is encrypted;

[0074] When the file density of the file block is less than a predetermined threshold, the file block is not encrypted;

[0075] In this step, whether to encrypt is determined based on the file density, thereby achieving the purpose of partial encryption.

[0076] Step S1.3, the two-dimensional code conversion device generates the first n1 groups of data packets, i.e., file description information, according to the file name, file size, and file hash value; the two-dimensional code conversion device converts the first n1 groups of data packets into the first Aztec code and outputs them to the display system, where n1 is a positive integer;

[0077] Step S1.4, the two-dimensional code conversion device disassembles the compressed file, and generates n2 intermediate data packets, i.e., the file body content, through all the file blocks that have been partially encrypted; the two-dimensional code conversion device converts the n2 intermediate data packets into the second Aztec code and outputs them to the display system, where n2 is a positive integer;

[0078] Step S1.5, the two-dimensional code conversion device generates an array with the number information of the encrypted file block, and converts it into the next n3 groups of data packets, i.e., the encrypted description information; the two-dimensional code conversion device converts the next n3 groups of data packets into the third Aztec code and outputs it to the display system, where n3 is a positive integer;

[0079] Step S2: Combine the QR code data through the QR code conversion device and restore it into a copy of the source file

[0080] Step S2.1, the two-dimensional code conversion device verifies whether all data packets have arrived completely and each data packet has passed the verification;

[0081] Step S2.2, the two-dimensional code conversion device finds the encrypted file block in the received file body content according to the data packet in the array corresponding to the number information of the encrypted file block in the received encrypted description information, and decrypts it;

[0082] Step S2.3, the QR code conversion device reassembles all the unencrypted file blocks and decrypted file blocks in the received file body content into a complete file in order;

[0083] Step S2.4, the QR code conversion device verifies the integrity of the file again according to the file hash value and file size described in the first n1 groups of data packets about the file name, file size, and file hash in the received file description information;

[0084] Step S2.5, the QR code conversion device decompresses the text content of the file to obtain a copy of the original file;

[0085] Step S2.6, the QR code conversion device saves the decompressed content as a temporary file name;

[0086] Step S2.7, the QR code conversion device uses the file name in the file description information to rename the temporary file name to the file name of the source file;

[0087] Step S2.8: The two-dimensional code conversion device transmits a copy of the original file to the destination file device.

[0088] In the present invention, the QR code conversion device divides the compressed file into multiple QR codes through the following technical solution:

[0089] Since there are different types of QR codes, this solution uses Aztec codes. Aztec codes are used because they can store the largest amount of data (3832 bytes) in a QR code image of a unit size. For example, a 100MB file can be transmitted by simply splitting the file into no more than 30,000 QR code image files.

[0090] In order to ensure that each Aztec QR code can store as much data as possible, a 151×151 module Aztec QR code is used for implementation. To optimize the display effect, the image size on the display screen is about 2.54 cm.

[0091] The Aztec QR code of 151×151 module can store up to 3832 bytes of data. To ensure the reliability of the transmitted data, the file to be transmitted will be disassembled / unpacked, and the size of each package is 3800 bytes.

[0092] In addition, to prevent files from being stolen, the original files need to be compressed and encrypted.

[0093] First, the original file is compressed using zip compression to reduce the file size and increase the transmission speed.

[0094] Secondly, the file needs to be encrypted. Unlike the usual way of encrypting the entire file, only part of the file is encrypted here. The advantage of partial encryption is that even if the file thief cannot get the complete unencrypted file, since the file is compressed, it is impossible to decrypt the file. Example 2

[0095] In embodiment 1, the method for partially encrypting a compressed file includes the following steps:

[0096] 1) Using the least squares method, a linear regression function is fitted to the file density of the file blocks obtained after the compressed file is disassembled;

[0097] 2) Calculate the sampling position. First, set the number of slices of the initial file. Here, the number of slices is determined according to the ratio of 1 / 1MB, that is, a 1MB initial file has 1 slice; a 10MB initial file has 10 slices, and so on.

[0098] The randomly sampled position p is:

[0099] ,

[0100] F is the total size of the file block, i represents the index of the slice, N represents the number of slices, S is the size of each slice (such as 1MB), and the rnd function is a random sampling function;

[0101] 3) Name the fitted function as df function, set the density factor as d, the file position (i.e. the random sampling position) as p, and the total size of the file block as F, then the density factor d is:

[0102] ,

[0103] 4) According to the random sampling position, the value of the density factor d of each sampling position is obtained; a threshold k is set, when the value of the density factor d is greater than k, the sampling is retained; when the value of the density factor d is less than or equal to k, the sampling is discarded;

[0104] 5) According to the sampled data that meets the conditions, the encrypted data is calculated and the original data is replaced to obtain the encrypted file block.

[0105] When transferring files, after compressing the original file, the least squares method is used to perform linear fitting according to the file density to generate a density fitting function (df function). Then, the random file block position is substituted into the density fitting function to calculate the density factor. The established threshold of the density factor is used to determine whether the file block needs to be encrypted. The entire algorithm process is a partial encryption algorithm.

[0106] Currently known encryption compression algorithms usually encrypt each file block of the compressed file.

[0107] For example, the RAR encryption algorithm usually uses three steps: key generation, encryption parameter setting, and block encryption to encrypt compressed files, as follows:

[0108] Key generation: RAR uses a cryptographically secure pseudo-random number generator to generate keys. This key is generated using a user-provided password and the seed of the pseudo-random number generator.

[0109] Encryption parameter setting: RAR encryption also requires setting encryption parameters, such as encryption mode, initialization vector and padding method. These parameters determine the specific behavior of the encryption algorithm.

[0110] Block encryption: RAR divides the file content into several fixed-size blocks, and then encrypts each block separately. This block encryption method makes the encryption process more efficient, and each block can use different encryption parameters, which increases the difficulty of cracking. The size of the block will change according to the size of the file and the encryption parameters of RAR.

[0111] The advantage of the present invention of using the density factor of the file to partially encrypt the compressed file is that only the more critical part (high density) of the file is encrypted, which can minimize the complexity of the file encryption process and reduce the occupation of computing resources. Example 3

[0112] In combination with Example 1 and Example 2, in step S1.2, the binary content of the compressed file is disassembled according to the set data packet structure, and the set data packet structure includes a packet header and a packet body, the packet header includes the file name, sequence number, total number of blocks, packet type, checksum and reserved area, and the packet body is the file content. The structural design of the data packet is shown in Table 1:

[0113] Table 1

[0114]

[0115] The overall transmission format is shown in Table 2:

[0116] Table 2

[0117] File description information (type code = 1) File body content (type code = 2) Encrypted description information (type code = 3) File name, file size, file hash value Document content Encrypted file block number information <![CDATA[n1 data packets]]> <![CDATA[n2 data packets]]> <![CDATA[n3 data packets]]>

[0118] Among them, the file hash value is calculated using the national encryption SM3 algorithm.

[0119] In the present invention, the encryption and decryption keys of the QR code disassembly and merging restoration program are stored in the QR code conversion device, which ensures that a third party cannot decrypt the encrypted QR code information during transmission (because they have no authority to obtain the keys). Example 4

[0120] In this embodiment, a separate two-dimensional code conversion device is provided to perform two-dimensional code generation and restoration operations. At the data source end, the two-dimensional code conversion device is connected to the source file device and the display system for displaying information via a network cable, such as Figure 1 shown.

[0121] At the data destination, the QR code conversion device is connected to the code scanning device and the destination file device (such as a server) for receiving files via a network cable. Figure 2 shown.

[0122] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for converting and restoring large files to QR codes, characterized in that The following steps are involved: Step S1: Conversion between large files and QR codes Step S1.1, transferring the original file to a QR code conversion device; Step S1.2, the two-dimensional code conversion device compresses the original file using a compression algorithm to obtain a compressed file; decomposes the compressed file into blocks to obtain file blocks; calculates the file density of each file block; When the file density of the file block is greater than a predetermined threshold, the file block is encrypted; When the file density of the file block is less than a predetermined threshold, the file block is not encrypted; Step S1.3, the two-dimensional code conversion device generates the first n1 groups of data packets, i.e., file description information, according to the file name, file size, and file hash value; the two-dimensional code conversion device converts the first n1 groups of data packets into the first Aztec code and outputs them to the display system, where n1 is a positive integer; Step S1.4, the two-dimensional code conversion device disassembles the compressed file, and generates n2 intermediate data packets, i.e., the file body content, through all the file blocks that have been partially encrypted; the two-dimensional code conversion device converts the n2 intermediate data packets into the second Aztec code and outputs them to the display system, where n2 is a positive integer; Step S1.5, the two-dimensional code conversion device generates an array with the number information of the encrypted file block, and converts it into the next n3 groups of data packets, i.e., the encrypted description information; the two-dimensional code conversion device converts the next n3 groups of data packets into the third Aztec code and outputs it to the display system, where n3 is a positive integer; Step S2: Combine the QR code data through the QR code conversion device and restore it into a copy of the source file Step S2.1, the two-dimensional code conversion device verifies whether all data packets have arrived completely and each data packet has passed the verification; Step S2.2, the two-dimensional code conversion device finds the encrypted file block in the received file body content according to the data packet in the array corresponding to the number information of the encrypted file block in the received encrypted description information, and decrypts it; Step S2.3, the QR code conversion device reassembles all the unencrypted file blocks and decrypted file blocks in the received file body content into a complete file in order; Step S2.4, the QR code conversion device verifies the integrity of the file again according to the file hash value and file size described in the first n1 groups of data packets about the file name, file size, and file hash value in the received file description information; Step S2.5, the QR code conversion device decompresses the text content of the file to obtain a copy of the original file; Step S2.6, the QR code conversion device saves the decompressed content as a temporary file name; Step S2.7, the QR code conversion device uses the file name in the file description information to rename the temporary file name to the file name of the source file; Step S2.8: The two-dimensional code conversion device transmits a copy of the original file to the destination file device.

2. The method for converting and restoring a large file to a two-dimensional code according to claim 1, characterized in that: In step S1.2, the binary content of the compressed file is disassembled according to the set data packet structure. The set data packet structure includes a header and a body. The header includes the file name, sequence number, total number of blocks, data packet type, checksum and reserved area, and the body is the file content.

3. The method for converting and restoring a large file to a two-dimensional code according to claim 1, characterized in that: The file hash value is calculated using the national secret SM3 algorithm.

4. The method for converting and restoring a large file to a two-dimensional code according to claim 1, characterized in that: The method for partially encrypting a compressed file includes the following steps: 1) Using the least squares method, a linear regression function is fitted to the file density of the file blocks obtained after the compressed file is disassembled; 2) Calculate the sampling position. The random sampling position p is: , F is the total size of the file block, i represents the index of the slice, N represents the number of slices, S is the size of each slice, and rnd function is a random sampling function; 3) Name the fitted function as df function, set the density factor as d, the file position (i.e. the random sampling position) as p, and the total size of the file block as F, then the density factor d is: , 4) According to the random sampling position, the value of the density factor d of each sampling position is obtained; a threshold k is set, when the value of the density factor d is greater than k, the sampling is retained; when the value of the density factor d is less than or equal to k, the sampling is discarded; 5) According to the sampled data that meets the conditions, the encrypted data is calculated and the original data is replaced to obtain the encrypted file block.

5. The method for converting and restoring a large file to a two-dimensional code according to claim 1, characterized in that: In step S1.2, the original file is compressed using a zip compression method.

6. A device for converting and restoring large files and QR codes, characterized in that: It comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps of the large file and two-dimensional code conversion and restoration method as described in any one of claims 1-5 are implemented.

7. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for converting and restoring a large file and a two-dimensional code as described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • High-capacity data transmission method and system based on two-dimensional code

    CN115378931A

  • File conversion method and conversion system

    CN115688688A