Two-dimensional code processing method, electronic device and readable storage medium
By performing hash calculation and digital signature encryption of QR code images on the sender, and determining whether to display QR code images based on digital signatures on the receiver, the problem of time-consuming and low security in the dynamic display of QR codes is solved, and faster generation and higher security are achieved.
Patent Information
- Application Number
- CN202411728861.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-04-01
AI Technical Summary
In the dynamic display scenario of QR code, the generation takes a long time due to the large amount of data, and the QR code image is easily intercepted and replaced during transmission, resulting in low application security.
Through the method applied to the sender, the QR code image is obtained and hashed is calculated. After obtaining the hash value, it is encrypted into a digital signature and sent to the receiver. The recipient determines whether to display the QR code image based on the digital signature to ensure its authenticity and integrity.
It reduces the time of QR code generation and the amount of data transmitted, improves the security of the dynamic display of QR codes, and ensures the authenticity and integrity of the displayed QR code images.
Smart Images

Figure CN119740592A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of two-dimensional codes, and in particular to a two-dimensional code processing method, an electronic device, and a readable storage medium. Background Art
[0002] A QR code is a black and white graphic that records data symbol information in a plane (two-dimensional direction) with a certain geometric shape distributed according to a certain rule. With the development of QR code technology, the application of QR code has penetrated into people's lives.
[0003] In dynamic display scenarios of QR codes, such as real-time updated QR codes, QR codes used to access resources for after-sales services of specific product models, electronic ticketing, etc., the amount of data covered by the QR code to be generated may be large, resulting in a long time to generate the QR code, and the QR code image is easily intercepted and replaced during transmission, and the wrong QR code image is displayed to the user, resulting in very low application security for dynamic QR code display. Summary of the invention
[0004] In order to solve at least one of the above technical problems, the embodiments of the present disclosure provide a two-dimensional code processing method, an electronic device and a readable storage medium. The technical solution is as follows: In a first aspect, an embodiment of the present disclosure provides a method for processing a two-dimensional code, characterized in that the method is applied to a sender and includes: Acquire a two-dimensional code image; the two-dimensional code image is obtained by converting the coding information obtained based on a set coding rule; the coding rule is used to process the first information generating the two-dimensional code image into second information and encode the second information to obtain the coding information; the data volume of the second information is less than the data volume of the first information; Performing a hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value; Encrypting the first hash value based on a pre-generated private key to obtain a digital signature; The two-dimensional code image and the digital signature are sent to a recipient, so that the recipient determines whether to display the two-dimensional code image based on the digital signature.
[0005] In a feasible embodiment, the encoding rule includes a rule corresponding to a QR code version determined based on an application scenario and a data volume of the first information; Encoding the second information based on the encoding rule includes: converting character information in the second information into encoding information corresponding to the encoding rule; Wherein, the two-dimensional code image includes an image obtained based on binary data after converting the coded information into binary data; When the user scans the two-dimensional code image displayed by the recipient, the resource corresponding to the first information is accessed through the second information.
[0006] In a feasible embodiment, obtaining a two-dimensional code image based on binary data includes: Determine a polynomial of a data codeword based on the binary data; Dividing the polynomial of the data codeword by a selected generator polynomial, and using the remainder obtained as an error correction codeword; the selected generator polynomial is related to the error correction level and the two-dimensional code version; The error correction codeword is used as redundant information and combined with the binary data to generate a two-dimensional code image.
[0007] In a feasible embodiment, performing hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value includes: Preprocessing the two-dimensional code image, wherein the preprocessing includes binarizing the two-dimensional code image and / or adjusting the size of the two-dimensional code image based on a preset threshold; Based on a preset hash function, a hash calculation is performed on the preprocessed two-dimensional code to obtain a first hash value of a fixed length.
[0008] In a feasible embodiment, the receiving party determines whether to display the two-dimensional code image based on the digital signature, including: When receiving the two-dimensional code image and the digital signature, the receiving party performs hash calculation on the two-dimensional code image based on the hash function to obtain a second hash value, and decrypts the digital signature based on the public key to obtain a third hash value, and if it is determined that the second hash value is the same as the third hash value, displays the two-dimensional code image, otherwise displays a prompt message indicating that the two-dimensional code image is invalid or wrong; The public key and the private key are associated with each other.
[0009] In a second aspect, an embodiment of the present disclosure provides a two-dimensional code processing method, which is applied to a receiver, and the method includes: Receive the QR code image and digital signature sent by the sender; Determining whether to display the QR code image based on the digital signature; The two-dimensional code image is obtained by converting the coding information obtained based on the set coding rule; the coding rule is used to process the first information generating the two-dimensional code image into the second information and encode the second information to obtain the coding information; the data volume of the second information is less than the data volume of the first information; The digital signature is obtained by the sender encrypting a first hash value using a preset private key, and the first hash value is obtained by performing a hash calculation on the two-dimensional code image based on a preset hash function.
[0010] In a feasible embodiment, determining whether to display the two-dimensional code image based on the digital signature includes: Performing a hash calculation on the two-dimensional code image based on a preset hash function to obtain a second hash value; Decrypting the digital signature based on a public key to obtain a third hash value; the public key is provided by the sender and is associated with a private key used by the sender; If the second hash value is the same as the third hash value, the two-dimensional code image is displayed; otherwise, a prompt message indicating that the two-dimensional code image is invalid or wrong is displayed.
[0011] In a feasible embodiment, the method further includes: In response to a scanning operation on the displayed two-dimensional code image, decoding the two-dimensional code image to obtain the second information; The resource corresponding to the first information is accessed through the second information.
[0012] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising at least one transceiver and at least one processor coupled to the at least one transceiver, wherein the at least one processor is configured to execute the steps of the method provided by the first aspect and any embodiment thereof or the second aspect and any embodiment thereof.
[0013] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect and any embodiment thereof or the second aspect and any embodiment thereof.
[0014] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, comprising a computer program, characterized in that when the computer program is executed by a processor, the steps of the method provided in the first aspect and any embodiment thereof or the second aspect and any embodiment thereof are implemented.
[0015] The technical solution provided by the embodiments of the present disclosure has the following beneficial effects: On the first aspect, the embodiments of the present disclosure provide a method for processing a two-dimensional code, which can be applied to a sender. Specifically, the two-dimensional code image obtained by the sender can be converted from the coding information obtained based on a set coding rule, and the coding rule is used to process the first information for generating the two-dimensional code image into second information and encode the second information to obtain the coding information, and the data amount of the second information is smaller than the data amount of the first information; that is, in the embodiments of the present disclosure, the obtained two-dimensional code image is the result of simplifying the data amount, and the simplification of the data amount is conducive to reducing the time for generating the two-dimensional code image and reducing the amount of data required to be transmitted; then, the sender can perform a hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value, and encrypt the first hash value based on a pre-generated private key to obtain a digital signature, and finally send the two-dimensional code image and the digital signature to the recipient, so that the recipient can determine whether to display the two-dimensional code image based on the digital signature, which is conducive to ensuring the authenticity and integrity of the displayed two-dimensional code image and improving the security of the dynamic display of the two-dimensional code.
[0016] In the second aspect, the embodiment of the present disclosure provides another two-dimensional code processing method, which can be applied to the receiving party. Specifically, when the receiving party receives the two-dimensional code image and digital signature sent by the sender, it can determine whether to display the two-dimensional code image based on the digital signature. Among them, the digital signature is obtained by the sender encrypting the first hash value through a preset private key, and the first hash value is obtained by hashing the two-dimensional code image based on a preset hash function. Compared with the prior art directly displaying the received two-dimensional code image, the implementation of the present disclosure can effectively ensure the authenticity and integrity of the displayed two-dimensional code image, and improve the application security of the dynamic display of the two-dimensional code. Among them, the two-dimensional code image is converted based on the coding information obtained by the set coding rule, and the coding rule is used to process the first information of the generated two-dimensional code image into the second information and encode the second information to obtain the coding information. The data volume of the second information is less than the data volume of the first information; compared with the prior art, the implementation of the present disclosure can effectively simplify the two-dimensional code information, reduce the time consumption of generating the two-dimensional code image, and reduce the amount of data required to be transmitted. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for describing the embodiments of the present disclosure are briefly introduced below.
[0018] Figure 1 A schematic diagram of a process for processing a two-dimensional code provided in an embodiment of the present disclosure; Figure 2 A schematic diagram of a flow chart of another two-dimensional code processing method provided in an embodiment of the present disclosure; Figure 3 A schematic diagram of processing a two-dimensional code image provided by an embodiment of the present disclosure; Figure 4 A schematic diagram of another processing method of a two-dimensional code image provided by an embodiment of the present disclosure; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0019] The embodiments of the present disclosure are described below in conjunction with the drawings in the present disclosure. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present disclosure and do not constitute a limitation on the technical solutions of the embodiments of the present disclosure.
[0020] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present disclosure refer to that the corresponding features can be implemented as the displayed features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" may be implemented as "A", or as "B", or as "A and B".
[0021] In order to make the objectives, technical solutions and advantages of the present disclosure more clear, the embodiments of the present disclosure will be further described in detail below with reference to the accompanying drawings.
[0022] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present disclosure and the technical effects produced by the technical solutions of the present disclosure. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0023] The following describes a method for processing a two-dimensional code provided in an embodiment of the present disclosure.
[0024] Specifically, Figure 1 As shown, the method applied to the sender includes S101 to S104: S101: Acquire a two-dimensional code image; the two-dimensional code image is obtained by converting coding information based on a set coding rule; the coding rule is used to process first information for generating the two-dimensional code image into second information; the data volume of the second information is smaller than the data volume of the first information.
[0025] Optionally, a QR code image is a specific geometric figure, in which a black and white rectangular array is distributed on a plane according to a certain rule, and is used to record data symbol information. The QR code image can be scanned and decoded by a specific device (such as a smart phone, a scanner), so as to quickly obtain the information contained therein.
[0026] Optionally, the set encoding rules can be used to compress, simplify or link the information of multiple QR codes into a single QR code, so as to reduce the information contained in the QR code, reduce the amount of data in the encoding and decoding process, and simplify the QR code.
[0027] Optionally, the first information may include information in a textual form, such as a URL, text information, etc., or may include information in a non-textual form, such as a picture, audio, video, etc.
[0028] In one example, the first information may include information corresponding to multiple resources, that is, it may include multiple copies of the first information, and when processed by the encoding rules, the multiple copies of the first information may be integrated to obtain one copy of the second information. Exemplarily, data such as smart device network binding, after-sales service, online customer service, and application download are integrated to form the second information for generating a QR code image. At this time, the resources corresponding to the multiple copies of the first information can be accessed through the QR code image generated by the second information. Compared with the prior art in which a QR code image is generated for each copy of the first information, the present disclosure implements the integration of multiple copies of the first information into one copy of the second information (or it may be the linking of multiple copies of the first information to an external link), and generates a QR code image based on the second information, which can reduce the number of QR code images generated, reduce the time spent on the production of the QR code image, and facilitate subsequent maintenance and management, thereby simplifying the final output QR code image. Optionally, in the process of integrating multiple copies of the first information, the data may be simplified, such as omitting the parameters of the non-specific part based on the set encoding rules, so that the amount of data of the integrated second information is less than the amount of data of the first information. Figure 3 and Figure 4 The comparison shows that compared with Figure 3 In terms of processing and transmitting each piece of information separately, Figure 4In the method, multiple information (such as the first information) can be integrated into information N (such as the second information), and a two-dimensional code image N is generated for the information N, and the single two-dimensional code image N is transmitted to the recipient. The user only needs to scan one two-dimensional code image N to read the resources corresponding to information 1, information 2 and information 3.
[0029] In one example, the first information may include information corresponding to a resource, such as a payment link. When the first information is processed based on the encoding rules, since the payment link may contain many non-specific parameters, in order to simplify the final generated QR code image, the first information can be compressed and simplified, and the non-specific parameters in the payment link are discarded to obtain the second information with reduced data volume.
[0030] Optionally, the coded information may be information obtained by encoding the second information based on the coding rule, and the QR code image may be a result obtained by converting the coded information. Exemplarily, a character encoding method such as ASCII code or UTF-8 encoding is used to convert the data to be encoded (such as text, numbers and other characters) into binary data, and the binary data is converted into black and white modules of specific rules.
[0031] The disclosed embodiment can realize the rapid generation of QR codes through the QR code generation IMS (Intelligent Management System), which can use the QR code generation library and API to connect with the sender. Optionally, the sender can be the subject of the QR code generation IMS system. That is, in the disclosed embodiment, the generation process of the QR code image can be executed by the sender, or it can be executed by a third party and then transmitted to the sender.
[0032] S102: Performing a hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value.
[0033] Optionally, the hash function may be a perceptual hash, an average hash, a difference hash, etc. The setting of the hash function may be adjusted according to actual needs, and the present disclosure does not limit this. The sender and the receiver use the same hash function to process the two-dimensional code image respectively, and compare the results of their respective hash calculations to determine the authenticity and integrity of the two-dimensional code image, thereby realizing the verification of the two-dimensional code image and improving the application security of the dynamic display of the two-dimensional code.
[0034] S103: Encrypt the first hash value based on a pre-generated private key to obtain a digital signature.
[0035] Optionally, the digital signature can be understood as the encrypted first hash value, and when the private key is used to encrypt the first hash value, a mathematical operation such as the RAS algorithm can be used to implement it. The encrypted digital signature and the QR code image can be sent or stored together for subsequent QR code image verification and integrity check.
[0036] Optionally, the private key is a key managed by the sender, and the sender can provide the receiver with a public key generated in pair with the private key so that the receiver can decrypt the digital signature through the public key. In one example, for application scenarios with low resource confidentiality requirements, such as viewing product manuals, the private key and public key can be used for a long time and do not need to be generated in real time. For application scenarios with high resource confidentiality requirements, such as payment, involving personal account information, etc., the private key and public key can be generated in real time or updated regularly, such as when a request to generate a QR code image is obtained, the private key and public key can be updated.
[0037] S104: Send the two-dimensional code image and the digital signature to a recipient, so that the recipient determines whether to display the two-dimensional code image based on the digital signature.
[0038] Optionally, after obtaining the digital signature based on the QR code image, the sender may send the QR code image and the digital signature together to the receiver, and the receiver may verify the received QR code image based on the digital signature.
[0039] Optionally, the encoding rules include rules corresponding to the QR code version determined based on the application scenario and the data volume of the first information.
[0040] Optionally, the encoding rules involve data encoding, error correction coding, data layout and format information. In different application scenarios, the encoding rules of the QR code used are different; for example, in application scenarios such as payment, identity authentication, and electronic ticketing, information security is the most important. At this time, a higher level of error correction coding and encryption technology can be set to protect sensitive information in the QR code. For example, compared with only a single algorithm for encryption, a hybrid encryption algorithm can be used for encryption in the electronic ticketing scenario, or physical encryption can be superimposed on the software algorithm encryption, such as superimposing visible lines under special lighting on the QR code, so that a specific barcode scanning instrument is required to read the QR code information. In logistics scenarios, since information is easily lost due to scratches, it is possible to set up encoding rules with higher fault tolerance to process the encoded data.
[0041] Optionally, the amount of data of the information to be encoded is different, and different encoding rules can also be set. In the embodiment of the present disclosure, it is intended to reduce the amount of information data used to generate a two-dimensional code image. To this end, when the first information used to generate a two-dimensional code image is obtained, it can be simply judged by the character length. If the character length is greater than the set threshold, it is determined that the amount of information data is large and needs to be simplified. If the character length is less than the set threshold, it is determined that the amount of information data is small, and a two-dimensional code image can be directly generated. Among them, the process of reducing the amount of information data can refer to the following examples: Take the first information as URL (Uniform Resource Locator) as an example: In the URL, the URL is composed of the protocol (https), domain name, path, query parameters (Query Strings) and other parts. The parameter part in the URL starts with a question mark (?), and the ampersand (&) is used to separate different parameters; each parameter is composed of a key (key) and a value (value), and the two are connected with an equal sign (=); Among them, considering that when multiple parameters need to be passed, the character length of the URL will increase significantly, the embodiment of the present disclosure can set valid characters to include parameters, and non-valid characters to include characters used to separate parameters and connect parameters. When counting the character length of the first information, valid characters can be counted, and when the number of valid characters is greater than a preset threshold, it is determined that the character length of the first information is greater than the preset threshold. In one example, for a URL, valid characters may include variable characters, and non-valid characters are characters other than valid characters in the characters that constitute the URL; variable characters refer to different characters in different URLs, such as the parameter won (such as the work order number) may be different in different URLs. In this case, the character corresponding to the parameter won is a variable character, and the same domain name in different URLs can be regarded as a non-variable character.
[0042] Take the first information as an example to illustrate: when the first information is processed based on characters, it is necessary to identify the picture to obtain the characters recorded in the picture. However, it is difficult to achieve 100% accuracy in character recognition. In order to improve the accuracy of processing for generating two-dimensional code information, the characters recognized from the picture can be distinguished whether they are effective, such as by analyzing context information and other means to determine whether each character is a valid character; the characters recognized from the picture can also be corrected. Exemplarily, there are some interfering lines in the picture, resulting in errors, omissions or increases in the recognized characters. For example, the character factor recorded in the picture may be underlined, and the character "f" therein may be recognized as "E", and the character "_" may be increased. At this time, the recognized characters can be distinguished and corrected whether they are effective, and "E" can be corrected to "f", and "_" can be determined as a non-valid character. After obtaining the processed valid characters, it can be determined whether the amount of information data needs to be reduced by the valid characters.
[0043] In the embodiment of the present disclosure, data processing can be performed on the first information with a long character length, aiming to reduce the amount of information ultimately used to generate the QR code and simplify the QR code. Optionally, the data processing can be performed in at least one of the following ways: Method 1, information simplification: The principle of information simplification is to simplify, abstract or extract key information from the first information to shorten the information length in the QR code. Specifically, the characters can be graded based on the preset generation rules of the QR code, and data simplification can be performed based on the level of the characters. For example, the sentence "This clothes drying machine has a drying function", in which keyword analysis is performed on the sentence, and the keywords "clothes drying machine" and "drying" can be obtained. Therefore, the keywords can be set to the required first level, and other characters or words can be set to the non-required second level. Therefore, a complex sentence can be simplified into two simple words "clothes drying machine" and "drying". In one example, the encoding rules of the QR code include multiple rules such as data encoding, error correction encoding, data layout, format information, positioning pattern, and color contrast. The above-mentioned sentence processing example can be a type of format information rule.
[0044] Method 2: Data compression: The principle of data compression is to use a data compression algorithm to encode the first information to compress the original information and reduce the amount of information used to generate the QR code. The data compression algorithm can be to use the frequency of occurrence of characters in the first information as a weight, generate a code by constructing a Huffman tree, and obtain a compression result with the shortest code length.
[0045] Method three, external link address: The overly long first information can be stored in a website (such as a URL), and the generated QR code can point to this website. After the user scans the QR code, the complete information can be obtained through network access. Exemplarily, the first information can be stored in the second information, and the second information is a short URL, and the second information points to the complete link (first information) on the external server. In the embodiment of the present disclosure, in order to simplify the URL in the QR code, a URL shortening service can be used to convert the long URL into a short URL, thereby reducing the complexity of the QR code and the space occupied.
[0046] Optionally, the QR code version indicates parameters such as the amount of information that can be stored in the QR code and the size of the QR code matrix. As the QR code version increases, the amount of information that can be stored in the QR code also increases. The encoding rules can be used to determine how to effectively store information in the QR code, and the QR code version used can determine the data capacity of the QR code.
[0047] The two-dimensional code image includes an image obtained based on binary data after converting the coding information into binary data.
[0048] Optionally, when the user scans the two-dimensional code image displayed by the recipient, the resource corresponding to the first information is accessed through the second information.
[0049] Optionally, after the receiving party shows the QR code image to the user, when the user scans the QR code image, the user can obtain the second information by decoding the QR code image, and obtain the first information by restoring the second information, and then access the resource corresponding to the first information. For example, when the first information is a URL, the SN (device unique) code recorded in the second information (which is a required parameter in the URL and can identify the unique device to be accessed) can be used to automatically associate other parameters in the URL corresponding to the SN code in the server to obtain the complete first information.
[0050] In the disclosed embodiments, the reduction in the data stored in the QR code can reduce the number of pixels in the QR code, making the QR code pattern more concise, clear and more readable, and also reducing the storage space occupied, thereby improving the scanning speed and accuracy of the scanning device, so that users can identify and read the QR code content more quickly. The reduction in the amount of information in the QR code can reduce the possibility of decoding errors or duplicate data due to excessive data volume, which is conducive to improving the stability and reliability of the QR code and ensuring that users can smoothly access the required information or services.
[0051] Optionally, obtaining a two-dimensional code image based on binary data includes steps A1 to A3: Step A1: Determine a polynomial of a data codeword based on the binary data.
[0052] Step A2: Divide the polynomial of the data codeword by a selected generating polynomial, and use the remainder obtained as the error correction codeword; the selected generating polynomial is related to the error correction level and the two-dimensional code version.
[0053] Step A3: The error correction codeword is used as redundant information and combined with the binary data to generate a two-dimensional code image.
[0054] Optionally, when a two-dimensional code image is obtained based on binary data, error correction code words may be added to improve the fault tolerance and reliability of the two-dimensional code image.
[0055] When determining the polynomial of a data codeword based on binary data, the degree of the polynomial can be determined according to the number of bits of the binary data. For example, an n-bit binary data can be represented as 2^n different states, corresponding to an n-degree polynomial. Then, each bit in the binary data can be regarded as a coefficient and arranged in order from high to low to form a coefficient sequence of the polynomial. Finally, the coefficients can be combined to form a polynomial.
[0056] For example, suppose there is a binary data sequence: 1101. The binary data can be converted into the corresponding decimal value: 12^3 + 12^2 + 02^1 + 12^0 = 13. Select a suitable generating polynomial, for example: g(x) = x^4 + x^2 + 1 (the corresponding binary form is: 10101), and then use modulo 2 division (XOR operation) to calculate the error correction codeword. Among them, the dividend: 13 (1101) in binary form is supplemented with 4 zeros (corresponding to the degree of the generating polynomial) to obtain 11010000; the divisor: the binary form of the generating polynomial g(x) 10101, performing modulo 2 division operation, the remainder can be obtained: 00111, and then the remainder is added to the original data as an error correction codeword (such as redundant information, check code), and the final data codeword is obtained: 11010011. That is, the original data is 1101, the generating polynomial is 10101, and the processed data codeword is 11010011.
[0057] In a feasible embodiment, performing hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value in S102 includes S102a to S102b: S102a: Preprocessing the two-dimensional code image, wherein the preprocessing includes binarizing the two-dimensional code image and / or adjusting the size of the two-dimensional code image based on a preset threshold.
[0058] S102b: Based on a preset hash function, perform hash calculation on the preprocessed two-dimensional code to obtain a first hash value of a fixed length.
[0059] Optionally, in order to improve the accuracy of the hash algorithm in extracting features from the QR code image, and thereby improve the accuracy of subsequent QR code image verification based on the hash value, the QR code image is also preprocessed before the hash calculation is performed on the QR code image in the embodiment of the present disclosure, such as removing noise, balancing brightness, and adjusting size and contrast to ensure image clarity.
[0060] Optionally, the specific operations of the preprocessing may include at least one of the following: Binarization processing: The QR code image can be converted into a black and white binary image by setting a threshold, which is convenient for subsequent processing.
[0061] Image scaling: Scale the image according to the size and position of the QR code to ensure that the QR code image is within the processing area.
[0062] Noise removal: Use median filtering, Gaussian filtering and other methods to remove noise points in the image.
[0063] Image rotation correction: Detect the four corner points of the QR code through Hough transform, calculate the angle and perform image rotation correction.
[0064] Image enhancement: Enhance image contrast and improve QR code recognition rate through methods such as histogram equalization.
[0065] Optionally, preprocessing the QR code image can eliminate noise, correct errors and adjust the size to ensure the integrity and consistency of the QR code. Preprocessing before hash calculation can make different versions of QR codes obtain hash values of fixed length after hash calculation, which is conducive to simplifying subsequent processing steps, such as hash value comparison, and improving processing efficiency.
[0066] Optionally, considering that the preprocessing step has a certain impact on the hash result, in the embodiment of the present disclosure, the sender and the receiver may use the same preprocessing step to process the QR code image to ensure the consistency of the preprocessing.
[0067] In a feasible embodiment, the recipient determines whether to display the QR code image based on the digital signature, including: when the recipient receives the QR code image and the digital signature, the recipient performs a hash calculation on the QR code image based on the hash function to obtain a second hash value, and decrypts the digital signature based on the public key to obtain a third hash value; if it is determined that the second hash value is the same as the third hash value, the QR code image is displayed, otherwise a prompt message indicating that the QR code image is invalid or wrong is displayed; wherein the public key and the private key are associated with each other.
[0068] Optionally, the sender may send the QR code image and the digital signature to the receiver together. When the receiver receives the QR code image, if the digital signature is also received, the QR code image may not be displayed temporarily, but the QR code image verification process may be entered.
[0069] During the verification process, the receiving party can use the same hash function as the sending party to perform hash calculation on the QR code image to obtain a second hash value, and decrypt the received digital signature based on the public key to obtain a third hash value. It can be understood that the hash function used by both parties is the same, and the public key is a key paired with the private key provided by the sending party to the receiving party. On this basis, if the QR code image received by the receiving party is authentic and complete, the second hash value is the same as the third hash value. Therefore, in the disclosed embodiment, it can be determined whether to display the QR code image by comparing the second hash value and the third hash value.
[0070] Optionally, when it is determined that the second hash value is different from the third hash value, a prompt message indicating that the QR code image is invalid or wrong can be displayed to prompt the user to be vigilant. The prompt message can be displayed in the area originally used to display the QR code image, replacing the QR code image, so that the user can directly perceive that there is a problem with the application of the current QR code image.
[0071] Another two-dimensional code processing method provided in an embodiment of the present disclosure is described below.
[0072] Specifically, Figure 2 As shown, the method applied to the receiving party may include S201 to S202: S201. Receive the QR code image and digital signature sent by the sender.
[0073] S202: Determine whether to display the two-dimensional code image based on the digital signature.
[0074] Among them, the two-dimensional code image is obtained by converting the coding information based on the set coding rules; the coding rules are used to process the first information generating the two-dimensional code image into second information; the data volume of the second information is smaller than the data volume of the first information.
[0075] The digital signature is obtained by the sender encrypting a first hash value using a preset private key, and the first hash value is obtained by performing a hash calculation on the two-dimensional code image based on a preset hash function.
[0076] Optionally, if the QR code image needs to be verified, such as in payment scenarios, to avoid malicious interception during data transmission and the use of another person's QR code to replace the original QR code, resulting in payment errors, the sender can simultaneously send a digital signature based on the QR code image when transmitting the QR code image. On this basis, if the receiver receives the digital signature when receiving the QR code image, the QR code image can be verified based on the digital signature, and the received QR code image will be displayed to the user only when the verification passes.
[0077] In a feasible embodiment, determining whether to display the two-dimensional code image based on the digital signature in S202 includes S202a to S202c: S202a: Performing hash calculation on the two-dimensional code image based on a preset hash function to obtain a second hash value.
[0078] Optionally, the sender and the receiver use the same hash function, and the two parties can agree on the hash function to be used before performing the interaction based on the QR code image. In particular, the sender performs the same operations involved in the hash calculation of the two-dimensional image, and the receiver will also perform the same operations, such as pre-processing of the QR code image, to maintain the consistency of the processing.
[0079] S202b: Decrypt the digital signature based on a public key to obtain a third hash value; the public key is provided by the sender and is associated with a private key used by the sender.
[0080] Optionally, the public key is provided by the sender to the receiver, and the public key is a private key generated in pairs with the private key. The private key is stored and used by the sender, while the public key can be disclosed to the object with which the sender communicates. The sender can use the private key to encrypt the hash value, and the receiver can use the public key to decrypt the digital signature.
[0081] S202c: If the second hash value is the same as the third hash value, display the two-dimensional code image; otherwise, display a prompt message indicating that the two-dimensional code image is invalid or wrong.
[0082] Optionally, since the sender and the receiver use the same hash function and perform the same processing, when the QR code image received by the receiver is authentic and complete (the same as the QR code image sent by the sender), the first hash value obtained by the sender performing hash calculation on the QR code image is the same as the second hash value obtained by the receiver performing hash calculation on the QR code image. On this basis, the receiver decrypts the digital signature based on the public key to obtain a third hash value. When the digital signature received by the receiver is consistent with the digital signature sent by the sender, the third hash value is the same as the first hash value. On this basis, the second hash value and the third hash value obtained by the receiver performing steps S202a and S202b can be directly compared, and whether to display the QR code image can be confirmed based on the comparison result.
[0083] Optionally, when the second hash value and the third hash value are the same, it indicates that the QR code image received by the recipient is authentic and complete, and the QR code image can be displayed to the user. When the second hash value and the third hash value are different, it indicates that the authenticity of the QR code image received by the recipient is questionable and some information may be lost, and a prompt message indicating that the QR code image is invalid or wrong can be displayed to the user. This prompt message can prompt the user to be vigilant on the one hand, and on the other hand, it can prompt the user to re-initiate a scan request to avoid long waiting times and reduce user experience.
[0084] Optionally, when comparing whether the second hash value and the third hash value are the same, the two hash values can be compared character by character. If at least 99% (this percentage is just an example and can be adjusted according to actual needs) of the characters are the same, it means that the two hash values are the same; otherwise, it means that the two hash values are different. In one example, a programming language can also be used to compare two hash values. For example, in Python, the compare_digest function of the hashlib module can be used to compare two hash values.
[0085] In a feasible embodiment, the method provided by the embodiment of the present disclosure also includes S203: in response to a scanning operation on the displayed QR code image, accessing resources corresponding to the first information through the second information; wherein the encoded information includes information obtained by encoding the second information based on the encoding rule.
[0086] Optionally, after the receiving party displays the QR code image to the user, the user can scan the QR code image to read the corresponding resource.
[0087] Optionally, the scanning operation can be initiated by the user using a scanning device to scan a QR code image displayed on a device on the receiving side, or the QR code is displayed on an electronic device used by the user and is initiated by identifying the QR code image.
[0088] Optionally, in the background operation, in response to the scanning operation of the QR code image, the QR code image can be decoded to obtain the second information used to generate the QR code image, and then the resource corresponding to the first information can be accessed through the second information. For example, when multiple first information are linked to external links to obtain the second information, the second information can be returned to the first information to read the resource corresponding to the first information.
[0089] Optionally, the above-mentioned verification operation on the two-dimensional code image (such as generating a digital signature to confirm the authenticity and integrity of the two-dimensional code image) can be initiated by the sender, the receiver or the user.
[0090] Optionally, the parts of step S201 to step S202 corresponding to step S101 to step S104 may refer to each other in various embodiments, and the present disclosure will not go into details here.
[0091] The following feasible application examples are given to further explain the embodiments of the present disclosure.
[0092] Application scenario: Scan the QR code to pay parking fees when leaving the parking lot When a user drives into a parking lot with a temporary license plate, the monitoring device cannot recognize the temporary license plate. When the user drives away, the call operation of the parking lot exit monitoring device can be triggered. The background of the monitoring device acts as the sender through a call with the user. When the user receives the request to drive away, the sender generates a QR code image for payment based on the temporary license plate input by the user and sends it to the front end of the monitoring device or the QR code display device (as the receiver) for display. At this time, since the QR code image is generated for a specific vehicle and a specific fee, in order to avoid the problem that others implement QR code replacement during the transmission of the QR code image, so that the user pays the parking fee to others but cannot leave, the sender can start the QR code image verification program, generate a digital signature for the QR code image, and send it to the receiver. The receiver confirms the authenticity and integrity of the QR code image based on the digital signature to display the correct QR code image to the user. After scanning the QR code image with a smartphone, the user can enter the payment program and pay the parking fee.
[0093] Application scenario: Smart door lock after-sales service Due to dust on the fingerprint recognition part of the smart door lock, or slight water marks on the user's finger, the smart door lock may fail to recognize the fingerprint. When the number of fingerprint recognition failures of the smart door lock reaches the set number, the smart door lock may enter the lock mode and cannot open the door. At this time, the user can initiate an unlock request through the smart door lock or the client bound to the smart door lock. After receiving the unlock request, the server connected to the smart door lock can integrate the instructions for use, after-sales consultation link, unlocking module operation instructions and other information corresponding to the smart door lock into the same information (such as the second information), and generate a QR code image to feedback to the user. At this time, since the information covered by the QR code image fed back to the user involves specific services of a specific product, in order to avoid information leakage and reduce the security of the use of the smart door lock, the sender can start the verification program of the QR code image, generate a digital signature for the QR code image through the above steps S101 to S104, and send the digital signature and the QR code image to the receiver (such as the smart door lock / client), and the receiver can verify the QR code image based on the digital signature, and after determining the authenticity and integrity of the QR code image, display the QR code image to the user. Then, after receiving the operation initiated by the user scanning the QR code image, the QR code image is decoded to obtain the second information. At this time, a page can be provided to the user to select the required information to be read. For example, the page can be laid out with operation entrances for information resources such as instructions for use, after-sales consultation, and unlocking module operation instructions. The user can read the corresponding information by selecting one of the entrances.
[0094] The QR code processing method provided by the disclosed embodiment reduces the cost and error rate of QR code production, maintenance and management from a technical perspective, and also reduces the troubles caused by users scanning the wrong QR code by mistake. By processing the first information into the second information through the coding rules, the amount of information data used to generate the QR code is reduced, and users can access or read multiple information or services by scanning only one QR code, thereby improving the efficiency and convenience of user code scanning. Figure 3 and Figure 4 visible, Figure 3 The sender processes each piece of information separately and transmits multiple QR code images to the receiver for display; Figure 4 The sender can integrate multiple information into information N, and in the subsequent steps generate a QR code image N for the information N, and transmit the QR code image N to the receiver. The receiver only needs to display one QR code image N, which can effectively reduce the area used to display the QR code image. In the end, the user only needs to scan one QR code image N to read the resources of each information through the information N, which is also conducive to improving the efficiency and convenience of user scanning.
[0095] In addition, the QR code verification solution provided by the embodiment of the present disclosure can also effectively protect information security, avoid the leakage of privacy information, the spread of malware (such as the displayed QR code image may be linked to malware during the transmission process, causing the user's device to be infected when scanning the code, resulting in data loss or device damage, etc.), and fraud (such as the QR code image is replaced, causing the user to scan the code to enter a fake payment page or download malware).
[0096] It should be noted that in the optional embodiments of the present disclosure, the information involved (such as QR code images, hash values, digital signatures, private keys, public keys and other related data), when the above embodiments of the present disclosure are applied to specific products or technologies, needs to obtain permission or consent from the user, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present disclosure involve data related to the object, these data need to be obtained with the authorization and consent of the object and in compliance with the relevant laws, regulations and standards of the country and region.
[0097] The embodiment of the present disclosure provides a two-dimensional code processing device, which is applied to a sender. The two-dimensional code processing device may include: an acquisition module, a hash calculation module, an encryption module and a sending module.
[0098] Among them, the acquisition module is used to acquire a two-dimensional code image; the two-dimensional code image is converted from the coding information obtained based on the set coding rules; the coding rules are used to process the first information for generating the two-dimensional code image into second information; the data volume of the second information is less than the data volume of the first information; the hash calculation module is used to perform hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value; the encryption module is used to encrypt the first hash value based on a pre-generated private key to obtain a digital signature; the sending module is used to send the two-dimensional code image and the digital signature to the recipient, so that the recipient determines whether to display the two-dimensional code image based on the digital signature.
[0099] In another embodiment of the present disclosure, another two-dimensional code processing device is provided, which is applied to a receiver. The device may include: a receiving module and a determining module.
[0100] Among them, the receiving module is used to receive the two-dimensional code image and digital signature sent by the sender; the determining module is used to determine whether to display the two-dimensional code image based on the digital signature.
[0101] Wherein, the two-dimensional code image is converted from the coding information obtained based on the set coding rules; the coding rules are used to process the first information for generating the two-dimensional code image into second information; the data volume of the second information is smaller than the data volume of the first information; wherein, the digital signature is obtained by the sender encrypting the first hash value through a preset private key, and the first hash value is obtained by hashing the two-dimensional code image based on a preset hash function.
[0102] The device of the embodiments of the present disclosure can execute the method provided by the embodiments of the present disclosure, and the implementation principles are similar. The actions performed by each module in the device of each embodiment of the present disclosure correspond to the steps in the method of each embodiment of the present disclosure. For the detailed functional description of each module of the device, please refer to the description in the corresponding method shown in the previous text, which will not be repeated here.
[0103] The modules involved in the embodiments described in the present disclosure may be implemented by software. The name of the module does not limit the module itself in some cases. For example, the acquisition module may also be described as a "module for acquiring a QR code image", "a first module", etc.
[0104] In an embodiment of the present disclosure, an electronic device is provided, wherein a host of the device includes a memory, a processor, and a computer program stored in the memory, and the processor executes the above-mentioned computer program to implement the steps of the two-dimensional code processing method. Compared with the related art, the following can be achieved: Compared with the prior art directly displaying the received two-dimensional code image, the implementation of the present disclosure can effectively ensure the authenticity and integrity of the displayed two-dimensional code image, and improve the application security of the dynamic display of the two-dimensional code. Among them, the two-dimensional code image is obtained by converting the coding information obtained based on the set coding rules, and the coding rules are used to process the first information for generating the two-dimensional code image into the second information, and the data volume of the second information is less than the data volume of the first information; compared with the prior art, the implementation of the present disclosure can effectively simplify the two-dimensional code information, reduce the time consumption of generating the two-dimensional code image, and reduce the amount of data required to be transmitted.
[0105] In an alternative embodiment, an electronic device is provided, such as Figure 5 As shown, Figure 5 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present disclosure.
[0106] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present invention. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0107] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0108] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.
[0109] The memory 4003 is used to store the computer program for executing the embodiment of the present disclosure, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the above method embodiment.
[0110] Among them, electronic devices include but are not limited to: terminal devices and servers.
[0111] An embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.
[0112] The embodiments of the present disclosure also provide a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiments when executed by a processor.
[0113] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than that shown or described in the text.
[0114] It should be understood that, although the flowchart of the embodiment of the present disclosure indicates each operation step by arrows, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present disclosure, the implementation steps in each flowchart can be executed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage in these sub-steps or stages can also be executed at different times. In scenarios with different execution times, the execution order of these sub-steps or stages can be flexibly configured according to demand, and the embodiment of the present disclosure does not limit this.
[0115] The above is only an optional implementation method for some implementation scenarios of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the scheme of the present disclosure, other similar implementation methods based on the technical ideas of the present disclosure are also within the protection scope of the embodiments of the present disclosure.
Claims
1. A two-dimensional code processing method, characterized in that: Applied to the sender, the method comprises: Acquire a two-dimensional code image; the two-dimensional code image is obtained by converting the coding information obtained based on a set coding rule; the coding rule is used to process the first information generating the two-dimensional code image into second information and encode the second information to obtain the coding information; the data volume of the second information is less than the data volume of the first information; Performing a hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value; Encrypting the first hash value based on a pre-generated private key to obtain a digital signature; The two-dimensional code image and the digital signature are sent to a recipient, so that the recipient determines whether to display the two-dimensional code image based on the digital signature.
2. The method according to claim 1, characterized in that The encoding rules include rules corresponding to the QR code version determined based on the application scenario and the data volume of the first information; Wherein, the two-dimensional code image includes an image obtained based on binary data after converting the coded information into binary data; When the user scans the two-dimensional code image displayed by the recipient, the resource corresponding to the first information is accessed through the second information.
3. The method according to claim 2, characterized in that Obtain a QR code image based on binary data, including: Determine a polynomial of a data codeword based on the binary data; Dividing the polynomial of the data codeword by a selected generator polynomial, and using the remainder obtained as an error correction codeword; the selected generator polynomial is related to the error correction level and the two-dimensional code version; The error correction codeword is used as redundant information and combined with the binary data to generate a two-dimensional code image.
4. The method according to claim 1, characterized in that: The performing hash calculation on the two-dimensional code image based on a preset hash function to obtain a first hash value includes: Preprocessing the two-dimensional code image, wherein the preprocessing includes binarizing the two-dimensional code image and / or adjusting the size of the two-dimensional code image based on a preset threshold; Based on a preset hash function, a hash calculation is performed on the preprocessed two-dimensional code to obtain a first hash value of a fixed length.
5. The method according to claim 1, characterized in that The receiving party determines whether to display the two-dimensional code image based on the digital signature, including: When receiving the two-dimensional code image and the digital signature, the receiving party performs hash calculation on the two-dimensional code image based on the hash function to obtain a second hash value, and decrypts the digital signature based on the public key to obtain a third hash value, and if it is determined that the second hash value is the same as the third hash value, displays the two-dimensional code image, otherwise displays a prompt message indicating that the two-dimensional code image is invalid or wrong; The public key and the private key are associated with each other.
6. A two-dimensional code processing method, characterized in that: Applied to a receiving party, the method comprises: Receive the QR code image and digital signature sent by the sender; Determining whether to display the QR code image based on the digital signature; The two-dimensional code image is obtained by converting the coding information obtained based on the set coding rule; the coding rule is used to process the first information generating the two-dimensional code image into the second information and encode the second information to obtain the coding information; the data volume of the second information is less than the data volume of the first information; The digital signature is obtained by the sender encrypting a first hash value using a preset private key, and the first hash value is obtained by performing a hash calculation on the two-dimensional code image based on a preset hash function.
7. The method according to claim 6, characterized in that The determining whether to display the two-dimensional code image based on the digital signature includes: Performing a hash calculation on the two-dimensional code image based on a preset hash function to obtain a second hash value; Decrypting the digital signature based on a public key to obtain a third hash value; the public key is provided by the sender and is associated with a private key used by the sender; If the second hash value is the same as the third hash value, the two-dimensional code image is displayed; otherwise, a prompt message indicating that the two-dimensional code image is invalid or wrong is displayed.
8. The method according to claim 6 or 7, characterized in that: The method further comprises: In response to a scanning operation on the displayed two-dimensional code image, decoding the two-dimensional code image to obtain the second information; The resource corresponding to the first information is accessed through the second information.
9. An electronic device, characterized in that: The electronic device comprises at least one transceiver and at least one processor coupled to the at least one transceiver, wherein the at least one processor is configured to perform the steps of the method according to any one of claims 1 to 5 or 6 to 8.
10. A computer-readable 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 according to any one of claims 1 to 5 or 6 to 8 are implemented.
Citation Information
Cited By
Complexity-based two-dimensional code generation method
CN120337964A