Two-dimensional code verification method, device, equipment, medium and program product
By identifying and segmenting the device information QR code string during the QR code verification stage, and combining server-side random strings and hash algorithms, the security issue of QR code stored information is solved, achieving an efficient and secure verification process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- LINGSHU TECH CO LTD
- Filing Date
- 2026-04-03
- Publication Date
- 2026-07-31
AI Technical Summary
In IoT scenarios, the security of directly storing device information in QR codes is difficult to guarantee, and it is vulnerable to injection attacks by attackers.
The current string of the device information QR code is identified and segmented into device information, a random string, and a hash value. The random string obtained from the server is concatenated, and a hash algorithm is used to calculate and verify the hash value. The hash values are then compared to determine the verification result, avoiding complex encryption and decryption processes.
It improves the efficiency of QR code verification, reduces server-side resource consumption, enhances the security of device information, and prevents tampering.
Smart Images

Figure CN122491316A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Internet of Things (IoT) technology, and in particular to a QR code verification method, apparatus, device, medium, and program product. Background Technology
[0002] QR codes are ubiquitous in daily life. In IoT scenarios, device information is stored within QR codes to identify the current device. However, directly storing device information in QR codes can lead to direct injection attacks by attackers, making it difficult to guarantee the security of the device information stored in the QR code. Summary of the Invention
[0003] This invention provides a QR code verification method, apparatus, device, medium, and program product, which improves the security of device information stored in the QR code.
[0004] According to one aspect of the present invention, a QR code verification method is provided, applied on a server side, the method comprising: During the QR code verification phase, the current string of the device information QR code is identified; The current string is segmented to obtain the current device information, the current random string, and the current hash value; Obtain a random string from the server, and concatenate the random string from the server, the current device information, and the current random string to obtain a first concatenation result; The target hash algorithm is used to perform hash calculation on the first concatenation result to obtain the verification hash value; The current hash value and the verification hash value are compared, and the target verification result of the device information QR code is determined based on the hash value comparison result.
[0005] According to another aspect of the present invention, a QR code verification device is provided, applied to a server, the device comprising: The device information QR code recognition module is used to recognize the current string of the device information QR code during the QR code verification stage; The current string segmentation module is used to segment the current string to obtain current device information, current random string, and current hash value; The first concatenation result generation module is used to obtain a random string from the server and concatenate the random string from the server, the current device information, and the current random string to obtain a first concatenation result. The verification hash value calculation module is used to perform hash calculation on the first concatenation result using the target hash algorithm to obtain the verification hash value; The device information QR code verification module is used to compare the current hash value and the verification hash value, and determine the target verification result of the device information QR code based on the hash value comparison result.
[0006] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the QR code verification method according to any embodiment of the present invention.
[0007] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the QR code verification method according to any embodiment of the present invention.
[0008] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the QR code verification method according to any embodiment of the present invention.
[0009] The technical solution of this invention, during the QR code verification stage, identifies the current string of the device information QR code, segments the current string to obtain the current device information, a current random string, and a current hash value, obtains a server-side random string, and concatenates the server-side random string, the current device information, and the current random string to obtain a first concatenation result. A target hash algorithm is then used to perform hash calculation on the first concatenation result to obtain a verification hash value. The current hash value and the verification hash value are compared, and the target verification result of the device information QR code is determined based on the hash value comparison result. During the QR code verification stage, no complex encryption / decryption process is required, resulting in high QR code verification efficiency. Simultaneously, only the server-side random string needs to be stored, improving the security of the device information QR code with low server-side resource consumption. Therefore, while maintaining QR code verification speed, tamper-proof verification of the device information stored in the QR code is achieved, improving the security of the device information stored in the QR code.
[0010] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of a QR code verification method provided in Embodiment 1 of the present invention; Figure 2 This is a flowchart of a QR code verification method provided in Embodiment 2 of the present invention; Figure 3 This is a flowchart of a QR code verification method provided in Embodiment 3 of the present invention; Figure 4 This is a schematic diagram of the structure of a QR code verification device according to Embodiment 4 of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device that implements the QR code verification method of this invention. Detailed Implementation
[0013] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0014] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0015] Example 1 Figure 1This is a flowchart illustrating a QR code verification method provided in Embodiment 1 of the present invention. This embodiment of the invention is applicable to QR code verification of IoT devices. The method can be executed by a QR code verification device, which can be implemented in hardware and / or software. This QR code verification device can be configured in an electronic device that carries QR code verification functionality, such as a server.
[0016] See Figure 1 The QR code verification methods shown include: S101. During the QR code verification phase, identify the current string of the device information QR code.
[0017] The QR code verification stage verifies whether the device information QR code has been tampered with. The device information QR code is used to store current device information. The current string is the direct recognition result of the device information QR code.
[0018] Specifically, during the QR code verification phase, the current string of the device information QR code recognized by the QR code scanning device is obtained.
[0019] In an optional embodiment of the present invention, after recognizing the current string of the device information QR code during the QR code verification stage, the method further includes: performing length detection and content verification on the current string; removing the current string if the length detection or content detection fails; and correspondingly, segmenting the current string to obtain the current device information, the current random string, and the current hash value, including: segmenting the current string to obtain the current device information, the current random string, and the current hash value when the length detection and content detection of the current string pass.
[0020] If the length check of the current string passes, it means that the length of the current string is within the length limit range of the device information QR code. If the length check fails, it means that the length of the current string exceeds the length limit range of the device information QR code. The length limit range is a pre-defined length range for a compliant string corresponding to the device information QR code. For example, the length limit range can be that the length of the current string is less than or equal to a preset string length. The preset string length is the maximum pre-defined length of the string corresponding to the device information QR code. The preset string length is used to measure the length compliance of the string corresponding to the device information QR code.
[0021] If the content check of the current string passes, it means that all characters in the current string are compliant. If the content check of the current string fails, it means that some characters in the current string contain non-compliant content. Optionally, a preset character set can be used to perform content check on the current string. The preset character set is a pre-defined set of compliant characters for the string corresponding to the device information QR code. The preset character set is used to measure the content compliance of the string corresponding to the device information QR code.
[0022] Removing the current string can be understood as deeming it unsuitable for formatting and thus preventing further QR code verification. This avoids wasting server resources by verifying non-compliant strings, enabling efficient use of server resources.
[0023] Specifically, during the QR code verification phase, after recognizing the current string of the device information QR code, a comparison can be made between the current string and a preset string length. If the current string length is less than or equal to the preset string length, the length check is considered passed; if the current string length is greater than the preset string length, the length check is considered failed. A comparison can also be made between the current string and a preset character set. If all content of the current string is contained within the preset character set, the content check is considered passed; if no content of the current string is contained within the preset character set, the content check is considered failed.
[0024] Specifically, if the length or content of the current string fails the length check or content check, the current string is discarded. If both the length and content checks of the current string pass, the current string is segmented using a preset segmentation rule to obtain the current device information, the current random string, and the current hash value.
[0025] This solution improves the compliance of the verified string during the QR code verification stage by performing length and content checks on the current string after recognizing it, thereby enhancing the fault tolerance of the QR code verification process.
[0026] S102. Segment the current string to obtain the current device information, the current random string, and the current hash value.
[0027] Current device information is used to characterize the attribute parameters of the current device. For example, current device information includes the device's identity information, functional information, status information, security information, and configuration information. Identity information includes device identifier, device name, device type, and device origin. Functional information includes communication capabilities, hardware parameters, execution capabilities, and power consumption. Status information includes real-time status, location information, time information, and resource usage status. Security information includes authentication information, permission configuration information, and security status. Configuration information includes device configuration information, maintenance information, and log events.
[0028] The current random string is a string randomly generated for the current device information during the QR code generation stage. This random string is used to enhance the security of the current device information QR code. The current hash value is a hash value obtained directly from the device information QR code. This hash value may be the original hash value generated during the QR code generation stage, or it may be a hash value that has been tampered with after the device information QR code was generated. Therefore, the current hash value is the hash value to be verified during the QR code verification stage.
[0029] Specifically, the current string can be segmented according to preset segmentation rules to obtain current device information, a current random string, and a current hash value. The preset segmentation rules are the pre-defined segmentation rules for the current string.
[0030] For example, the preset segmentation rule can be the number of digits in the current device information, the number of digits in the current random string, and the number of digits in the current hash value. Accordingly, the current string can be segmented based on the number of digits in the current device information, the number of digits in the current random string, and the number of digits in the current hash value to obtain the current device information, the current random string, and the current hash value.
[0031] In an optional embodiment of the present invention, segmenting the current string to obtain current device information, current random string and current hash value includes: identifying a reference delimiter in the current string; and segmenting the current string according to the reference delimiter to obtain current device information, current random string and current hash value.
[0032] A reference separator is used to separate different information within the current string. The content of the reference separator is distinct from the current device information, the current random string, and the current hash value. Optionally, the reference separator can be predetermined and stored in the device. For example, reference separators include comma separators, vertical bar separators, tab separators, colon separators, space separators, or other non-standard separators. Other non-standard separators include ";", "#", "^", or "&".
[0033] Specifically, a pre-generated reference delimiter can be obtained from this device. Based on the position of the reference delimiter, the current string can be split to obtain the current device information, the current random string, and the current hash value.
[0034] This solution introduces a reference separator, which enables rapid segmentation of the current string and improves the verification efficiency of device information QR codes.
[0035] S103. Obtain the random string from the server, and concatenate the random string from the server, the current device information, and the current random string to obtain the first concatenation result.
[0036] The server-side random string is a pre-generated string on the server. This random string is used to generate the verification hash value during the QR code verification phase and the current hash value during the QR code generation phase. The first concatenation result is the concatenation of the server-side random string from the QR code verification phase, the current device information, and the current random string.
[0037] Specifically, a pre-generated random string from the server can be obtained. Then, using a first preset concatenation rule corresponding to a preset segmentation rule, the server-side random string, the current device information, and the current random string are concatenated to obtain a first concatenation result. The first preset concatenation rule is used to concatenate the server-side random string, the current device information, and the current random string. For example, the first preset concatenation rule may include the order of different information and preset delimiters between each piece of information. The preset delimiter is a pre-defined separator between the server-side random string, the current device information, and the current random string. The preset delimiter and the reference delimiter can be the same or different.
[0038] S104. Using the target hash algorithm, perform hash calculation on the first concatenation result to obtain the verification hash value.
[0039] The target hash algorithm is used to perform hash calculations. For example, target hash algorithms include SHA-3 (Secure Hash Algorithm 3) or BLAKE 2 (BLAKE 2 Hash Function, a set of efficient cryptographic hash functions).
[0040] The verification hash value is a reference hash value used to verify whether the device information QR code has been tampered with. It can be understood as being generated based on the current device information, the current random string, and a server-side random string pre-stored on the server, all identified from the device information QR code. After the device information QR code is generated, the current device information, the current random string, and the current hash value can all be tampered with. In this case, the server-side random string is obtained from the server and combined with the current device information and the current random string identified from the device information QR code to generate the verification hash value. A consistency comparison is then performed between the current hash value and the verification hash value. If any of the current device information, the current random string, or the current hash value has been tampered with, the current hash value and the verification hash value will be inconsistent, thus verifying whether the device information QR code has been tampered with.
[0041] Furthermore, the device information QR code only stores the current device information, the current random string, and the current hash value. The server-side random string is required to generate the corresponding hash value. Therefore, attackers cannot directly generate the corresponding hash value based on the QR code's identification information, thus further enhancing the security of the device information QR code.
[0042] Specifically, a target hash algorithm can be used to perform hash calculations on the first concatenation result to obtain the verification hash value.
[0043] S105. Compare the current hash value and the verification hash value, and determine the target verification result of the device information QR code based on the hash value comparison result.
[0044] The hash value comparison result is the comparison between the current hash value and the verification hash value. The hash value comparison result is used to characterize the consistency between the current hash value and the verification hash value. For example, the hash value comparison result includes whether the current hash value and the verification hash value are consistent or inconsistent. Where the current hash value and the verification hash value are consistent, it can be understood that the current device information, the current random string, and the current hash value obtained from the device information QR code recognition have not been tampered with. Where the current hash value and the verification hash value are consistent, it can be understood that some content in the current device information, the current random string, and the current hash value obtained from the device information QR code recognition has been tampered with.
[0045] The target verification result is the verification result of the device information QR code. The target verification result is used to characterize whether the device information QR code has been tampered with. For example, the target verification result includes "device information QR code verification passed" and "device information QR code verification failed." "Device information QR code verification passed" can be understood as the device information QR code not being tampered with, and the current device information stored in the device information QR code is trustworthy. "Device information QR code verification failed" can be understood as the device information QR code being tampered with, and the current device information stored in the device information QR code is untrustworthy.
[0046] Specifically, the current hash value and the verification hash value can be compared. If the current hash value and the verification hash value match, the device information QR code verification is successful. If the current hash value and the verification hash value do not match, the device information QR code verification is unsuccessful.
[0047] The technical solution of this invention, during the QR code verification stage, identifies the current string of the device information QR code, segments the current string to obtain the current device information, a current random string, and a current hash value, obtains a server-side random string, and concatenates the server-side random string, the current device information, and the current random string to obtain a first concatenation result. A target hash algorithm is then used to perform hash calculation on the first concatenation result to obtain a verification hash value. The current hash value and the verification hash value are compared, and the target verification result of the device information QR code is determined based on the hash value comparison result. During the QR code verification stage, no complex encryption / decryption process is required, resulting in high QR code verification efficiency. Simultaneously, only the server-side random string needs to be stored, improving the security of the device information QR code with low server-side resource consumption. Therefore, while maintaining QR code verification speed, tamper-proof verification of the device information stored in the QR code is achieved, improving the security of the device information stored in the QR code.
[0048] Example 2 Figure 2This is a flowchart of a QR code verification method provided in Embodiment 2 of the present invention. Based on the above embodiments, this invention further adds the following steps before recognizing the current string of the device information QR code during the QR code verification stage: "During the QR code generation stage, upon detecting a QR code generation request, obtain the current device information and a server-side random string, and randomly generate a current random string; concatenate the current device information, the current random string, and the server-side random string to obtain a second concatenation result; use a target hash algorithm to perform hash calculation on the second concatenation result to obtain a current hash value; concatenate the current device information, the current random string, and the current hash value to obtain a third concatenation result; and generate the device information QR code based on the third concatenation result." In the process of generating the device information QR code, firstly, by introducing the current random string, the temporality and randomness of the device information QR code are improved; secondly, by introducing the server-side random string, the generation efficiency of the device information QR code can be improved, and it can also ensure that attackers cannot directly generate the corresponding hash value based on the identification information of the device information QR code, further improving the security of the device information QR code and the accuracy of the QR code verification process; finally, the overall method of generating the device information QR code is simplified, achieving tamper-proof protection of the device information stored in the QR code while maintaining QR code generation speed. It should be noted that for parts not described in detail in the embodiments of the present invention, please refer to the descriptions in other embodiments.
[0049] See Figure 2 The QR code verification methods shown include: S201. During the QR code generation stage, when a QR code generation request is detected, obtain the current device information and the server-side random string, and randomly generate the current random string.
[0050] The QR code generation stage is the stage for generating a QR code containing device information. The QR code generation request is used to request the generation of a QR code containing device information. This request includes the current device information.
[0051] Different device information QR codes correspond to different current random strings. This can be understood as generating a new random string for each device information QR code. Therefore, the temporality and randomness of the current random string improve the security of the generated device information QR code.
[0052] Different device information QR codes correspond to the same server-side random string. This can be understood as the server-side random string being pre-generated. During the generation of QR codes for different devices, the same server-side random string can be used, eliminating the need to repeatedly generate it. This improves the efficiency of device information QR code generation.
[0053] Specifically, during the QR code generation phase, upon detecting a user-sent QR code generation request, the current device information is extracted from the request. A pre-generated server-side random string stored on the device is obtained, and a random number generator is used to randomly generate the current random string.
[0054] In an optional embodiment of the present invention, before obtaining the current device information and server random string and randomly generating the current random string when a QR code generation request is detected during the QR code generation stage, the method further includes: during the server initialization stage, detecting whether a server random string exists; if no server random string exists, generating a server random string of a preset length.
[0055] The server initialization phase is the phase where the server is initialized. If the server does not have a pre-generated random string, it needs to be generated. The preset length is the pre-defined length of the server-side random string. For example, the preset length is 32 bits. Optionally, the length of the server-side random string can be greater than the length of the current random string. This prevents the server-side random string from being brute-forced.
[0056] Specifically, during the server initialization phase, it checks whether a server-side random string already exists. If no server-side random string exists, characters can be randomly selected from a preset character set to generate a server-side random string of a preset length.
[0057] Optionally, after generating a server-side random string of a preset length, the server-side random string can be stored in this device (i.e., the server). Accordingly, during the server initialization phase, if a server-side random string is detected, the server-side random string stored in this device is retrieved.
[0058] This solution improves the efficiency of QR code generation and verification by pre-generating a random string during the server initialization phase. Furthermore, generating a pre-defined length of random string prevents brute-force attacks on the random string, enhancing the security of both the random string and the device information QR code.
[0059] S202. Concatenate the current device information, the current random string, and the server random string to obtain the second concatenation result.
[0060] The second concatenation result is the concatenation result between the current device information, the current random string, and the server-side random string during the QR code generation stage.
[0061] Specifically, the first preset concatenation rule can be used to concatenate the random characters from the server, the current device information, and the current random string to obtain the first concatenation result.
[0062] S203. Using the target hash algorithm, perform hash calculation on the second concatenation result to obtain the current hash value.
[0063] S204. Concatenate the current device information, the current random string, and the current hash value to obtain the third concatenation result.
[0064] The third concatenation result is the concatenation result between the current device information, the current random string, and the current hash value during the QR code generation stage.
[0065] Specifically, the second preset concatenation rule corresponding to the preset segmentation rule can be used to concatenate the current device information, the current random string, and the current hash value to obtain the third concatenation result.
[0066] The second preset concatenation rule is used to concatenate the current device information, the current random string, and the current hash value. The second preset concatenation rule corresponds to the preset segmentation rule.
[0067] For example, if the preset segmentation rule is the order of different information and the number of digits in each piece of information, then the second preset concatenation rule can also be the order of different information and the number of digits in each piece of information. Accordingly, the number of digits in the current device information, the current random string, and the current hash value can be checked. If the number of digits in the current device information, the current random string, and the current hash value all pass the verification, then they can be directly concatenated according to the order of the different information. If the number of digits in the current device information, the current random string, or the current hash value is insufficient, preset characters can be used to pad the insufficient information at preset positions before concatenating the padded current device information, the current random string, and the current hash value according to the order of the different information. The preset characters are characters other than those in the current device information, the current random string, and the current hash value. Optionally, the preset characters need to be characters from a preset character set. For example, preset characters include "0" or "1". The preset positions include before the most significant digit or after the least significant digit.
[0068] For example, if the preset segmentation rule is the order of different information and the reference separator between different information, then the second preset concatenation rule can also be the order of different information and the reference separator between different information. Accordingly, the current device information, the current random string, and the current hash value can be directly concatenated according to the order of the current device information, the current random string, and the current hash value, as well as the reference separator.
[0069] In comparison, the first concatenation rule concatenates the server-side random string, the current device information, and the current random string. The second preset concatenation rule concatenates the current device information, the current random string, and the current hash value. Optionally, the second preset concatenation rule can be the same as or different from the first preset concatenation rule.
[0070] S205. Based on the third splicing result, generate a device information QR code.
[0071] Specifically, the third stitching result can be encoded, and the encoded data can be converted into a black and white pixel matrix to obtain a device information QR code.
[0072] S206. During the QR code verification phase, identify the current string of the device information QR code.
[0073] S207. Segment the current string to obtain the current device information, the current random string, and the current hash value.
[0074] S208. Obtain the random string from the server, and concatenate the random string from the server, the current device information, and the current random string to obtain the first concatenation result.
[0075] S209. Using the target hash algorithm, perform hash calculation on the first concatenation result to obtain the verification hash value.
[0076] S210. Compare the current hash value and the verification hash value, and determine the target verification result of the device information QR code based on the hash value comparison result.
[0077] The technical solution of this invention, during the QR code generation stage, upon detecting a QR code generation request, obtains current device information and a server-side random string, and randomly generates a current random string. The current device information, the current random string, and the server-side random string are concatenated to obtain a second concatenation result. A target hash algorithm is used to perform hash calculation on the second concatenation result to obtain a current hash value. The current device information, the current random string, and the current hash value are then concatenated to obtain a third concatenation result. Based on the third concatenation result, a device information QR code is generated. In the process of generating the device information QR code, firstly, by introducing the current random string, the temporality and randomness of the device information QR code are improved; secondly, by introducing the server-side random string, the generation efficiency of the device information QR code can be improved, and it can also ensure that attackers cannot directly generate the corresponding hash value based on the identification information of the device information QR code, further improving the security of the device information QR code and the accuracy of the QR code verification process; finally, the overall method of generating the device information QR code is simplified, achieving tamper-proof protection of the device information stored in the QR code while maintaining QR code generation speed.
[0078] In an optional embodiment of the present invention, concatenating the current device information, the current random string, and the current hash value to obtain a third concatenation result includes: concatenating the current device information, the current random string, the current hash value, and the target hash algorithm identifier to obtain a third concatenation result; correspondingly, segmenting the current string to obtain the current device information, the current random string, and the current hash value includes: segmenting the current string to obtain the current device information, the current random string, the current hash value, and the target hash algorithm identifier; correspondingly, performing a hash calculation on the first concatenation result using the target hash algorithm to obtain a verification hash value includes: detecting the target hash algorithm based on the target hash algorithm identifier; and performing a hash calculation on the first concatenation result using the target hash algorithm to obtain a verification hash value.
[0079] The target hash algorithm identifier is used to identify the target hash algorithm used in the hash calculation. For example, there can be multiple target hash algorithms. Accordingly, the target hash algorithm identifier can be used to distinguish different target hash algorithms.
[0080] Specifically, using the second preset concatenation rule, the current device information, the current random string, the current hash value, and the target hash algorithm identifier are concatenated to obtain the third concatenation result. A preset segmentation rule can be used to segment the current string, obtaining the current device information, the current random string, the current hash value, and the target hash algorithm identifier. The target hash algorithm corresponding to the target hash algorithm identifier can be detected. The target hash algorithm can be used to perform hash calculation on the first concatenation result to obtain a verification hash value.
[0081] This scheme introduces a target hash algorithm identifier, which distinguishes different target hash algorithms and improves the selectivity and flexibility of hash calculation.
[0082] Example 3 Figure 3 This is a flowchart of a QR code verification method provided in Embodiment 3 of the present invention. Based on the above embodiments, Figure 3 This is a preferred embodiment of a QR code verification method provided by the present invention.
[0083] See Figure 3 The QR code verification methods shown include: S301. During the server initialization phase, check if a server-side random string exists.
[0084] The server-side key files are all random strings generated by the server.
[0085] S302. If it does not exist, then generate a 32-bit server-side random string and save the server-side random string in a file.
[0086] If the key file does not exist, it means there is no key file. Both the high-entropy random string and the server key are server-side random strings.
[0087] S303. If it exists, then obtain the random string from the server.
[0088] The existence of a key file indicates that a key file exists.
[0089] S304. During the QR code generation stage, a QR code generation request sent by the user was detected.
[0090] The QR code generation request is used to request the generation of a device information QR code. The device identification QR code is the same as the device information QR code. The QR code generation request contains current device information.
[0091] S305. Perform a legality check on the current device information.
[0092] S306. When the validity check of the current device information passes, generate the current random string.
[0093] The temporary QR code random value is the current random string.
[0094] S307. Obtain a random string from the server.
[0095] S308. Concatenate the current device information, the current random string, and the server random string to obtain the second concatenation result.
[0096] The device identifier is the current device information. The random value of the QR code is the current random string.
[0097] S309. Using the SHA-3 algorithm, perform hash calculation on the second concatenation result to obtain the current hash value.
[0098] The QR code hash is the current hash value.
[0099] S310. Concatenate the current device information, the current random string, and the current hash value to obtain the third concatenation result.
[0100] S311. Based on the third splicing result, generate and return a device information QR code.
[0101] S312. If the validity check of the current device information fails, a QR code generation failure message will be sent.
[0102] The QR code generation failure message is used to indicate that the current device information is invalid or illegal.
[0103] S313. During the QR code verification stage, scan the device information QR code and obtain the current string.
[0104] The complete string is the current string.
[0105] S314. Perform a format validity check on the current string.
[0106] S315. When the current string format validity check passes, parse the current string to obtain the current device information, the current random string, and the current hash value.
[0107] S316. Obtain a random string from the server.
[0108] S317. Concatenate the current device information, the current random string, and the server random string to obtain the first concatenation result.
[0109] S318. Using the SHA-3 algorithm, perform hash calculation on the first concatenation result to obtain the verification hash value.
[0110] The verification hash is the verification hash value.
[0111] S319. Compare the current hash value with the verification hash value.
[0112] S320. When the current hash value and the verification hash value are consistent, the device information QR code verification is confirmed to be successful.
[0113] If the device information QR code verification is successful, it can be understood that the device information QR code is legitimate or has not been forged.
[0114] S321. If the current hash value and the verification hash value are inconsistent, determine that the device information QR code verification fails.
[0115] If the device information QR code verification fails, it can be understood that the device information QR code is invalid, forged, or tampered with.
[0116] S322. If the current string format validity check passes, a QR code verification failure message will be displayed.
[0117] The QR code verification failure message is used to indicate that the string format corresponding to the device information QR code is incorrect or invalid.
[0118] The technical solution of this invention achieves the generation and verification of device information QR codes without a complex encryption and decryption process. It requires no caching, consumes few resources, and while balancing generation and verification speeds, it also prevents tampering of the device information stored in the QR code, thus improving the security of the QR code.
[0119] Example 4 Figure 4 This is a schematic diagram of a QR code verification device provided in Embodiment 4 of the present invention. This embodiment of the invention is applicable to the verification of QR codes on IoT devices. The device can execute a QR code verification method and can be implemented in hardware and / or software. The device can be configured in an electronic device that carries QR code verification functionality, such as a server.
[0120] See Figure 4 The QR code verification device shown includes: a device information QR code recognition module 401, a current string segmentation module 402, a first concatenation result generation module 403, a verification hash value calculation module 404, and a device information QR code verification module 405. Specifically, the device information QR code recognition module 401 is used to recognize the current string of the device information QR code during the QR code verification stage; the current string segmentation module 402 is used to segment the current string to obtain current device information, a current random string, and a current hash value; the first concatenation result generation module 403 is used to obtain a server-side random string and concatenate the server-side random string, the current device information, and the current random string to obtain a first concatenation result; the verification hash value calculation module 404 is used to perform hash calculation on the first concatenation result using a target hash algorithm to obtain a verification hash value; and the device information QR code verification module 405 is used to compare the current hash value and the verification hash value, and determine the target verification result of the device information QR code based on the hash value comparison result.
[0121] The technical solution of this invention, during the QR code verification stage, identifies the current string of the device information QR code, segments the current string to obtain the current device information, a current random string, and a current hash value, obtains a server-side random string, and concatenates the server-side random string, the current device information, and the current random string to obtain a first concatenation result. A target hash algorithm is then used to perform hash calculation on the first concatenation result to obtain a verification hash value. The current hash value and the verification hash value are compared, and the target verification result of the device information QR code is determined based on the hash value comparison result. During the QR code verification stage, no complex encryption / decryption process is required, resulting in high QR code verification efficiency. Simultaneously, only the server-side random string needs to be stored, improving the security of the device information QR code with low server-side resource consumption. Therefore, while maintaining QR code verification speed, tamper-proof verification of the device information stored in the QR code is achieved, improving the security of the device information stored in the QR code.
[0122] In an optional embodiment of the present invention, the current string segmentation module 402 includes: a reference separator identification unit, used to identify a reference separator in the current string; and a current string segmentation unit, used to segment the current string according to the reference separator to obtain current device information, a current random string, and a current hash value.
[0123] In an optional embodiment of the present invention, the apparatus further includes: a current string verification module, configured to perform length detection and content verification on the current string after recognizing the current string of the device information QR code during the QR code verification stage; a current string removal module, configured to remove the current string when the length detection or content detection fails; correspondingly, the current string segmentation module 402 includes: a current string segmentation unit, configured to segment the current string when the length detection and content detection pass, to obtain current device information, a current random string, and a current hash value.
[0124] In an optional embodiment of the present invention, the apparatus further includes: a current random string generation module, configured to, during the QR code generation stage, before recognizing the current string of the device information QR code in the QR code verification stage, obtain the current device information and a server-side random string when a QR code generation request is detected, and randomly generate a current random string; a second concatenation result generation module, configured to concatenate the current device information, the current random string, and the server-side random string to obtain a second concatenation result; a current hash value calculation module, configured to perform hash calculation on the second concatenation result using a target hash algorithm to obtain a current hash value; a third concatenation result generation module, configured to concatenate the current device information, the current random string, and the current hash value to obtain a third concatenation result; and a device information QR code generation module, configured to generate a device information QR code based on the third concatenation result.
[0125] In an optional embodiment of the present invention, the apparatus further includes: a server-side random string detection module, configured to detect whether a server-side random string exists during the server-side initialization phase before obtaining current device information and a server-side random string and randomly generating the current random string when a QR code generation request is detected during the QR code generation phase; and a server-side random string generation module, configured to generate a server-side random string of a preset length if the server-side random string does not exist.
[0126] In an optional embodiment of the present invention, the third concatenation result generation module includes: a third concatenation result generation unit, used to concatenate the current device information, the current random string, the current hash value, and the target hash algorithm identifier to obtain a third concatenation result; correspondingly, the current string segmentation module 402 includes: a current string segmentation unit, used to segment the current string to obtain the current device information, the current random string, the current hash value, and the target hash algorithm identifier; correspondingly, the verification hash value calculation module 404 includes: a target hash algorithm detection unit, used to detect the target hash algorithm according to the target hash algorithm identifier; and a verification hash value calculation unit, used to perform hash calculation on the first concatenation result using the target hash algorithm to obtain a verification hash value.
[0127] The QR code verification device provided in this embodiment of the invention can execute the QR code verification method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0128] In the technical solutions of this invention, the acquisition, storage, and application of server-side random strings and current device information all comply with relevant laws and regulations and do not violate public order and good morals.
[0129] Example 5 Figure 5 A schematic diagram of an electronic device 500 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0130] like Figure 5As shown, the electronic device 500 includes at least one processor 501 and a memory, such as a read-only memory (ROM) 502 and a random access memory (RAM) 503, communicatively connected to the at least one processor 501. The memory stores computer programs executable by the at least one processor. The processor 501 can perform various appropriate actions and processes based on the computer program stored in the ROM 502 or loaded into the RAM 503 from storage unit 508. The RAM 503 can also store various programs and data required for the operation of the electronic device 500. The processor 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0131] Multiple components in electronic device 500 are connected to I / O interface 505, including: input unit 506, such as keyboard, mouse, etc.; output unit 507, such as various types of monitors, speakers, etc.; storage unit 508, such as disk, optical disk, etc.; and communication unit 509, such as network card, modem, wireless transceiver, etc. Communication unit 509 allows electronic device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0132] Processor 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 501 performs the various methods and processes described above, such as QR code verification methods.
[0133] In some embodiments, the QR code verification method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by processor 501, one or more steps of the QR code verification method described above may be performed. Alternatively, in other embodiments, processor 501 may be configured to perform the QR code verification method by any other suitable means (e.g., by means of firmware).
[0134] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0135] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0136] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0137] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0138] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0139] A computing system can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system. It addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability.
[0140] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0141] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A QR code verification method, characterized in that, Applied to the server side, the method includes: During the QR code verification phase, the current string of the device information QR code is identified; The current string is segmented to obtain the current device information, the current random string, and the current hash value; Obtain a random string from the server, and concatenate the random string from the server, the current device information, and the current random string to obtain a first concatenation result; The target hash algorithm is used to perform hash calculation on the first concatenation result to obtain the verification hash value; The current hash value and the verification hash value are compared, and the target verification result of the device information QR code is determined based on the hash value comparison result.
2. The method according to claim 1, characterized in that, The step of segmenting the current string to obtain the current device information, the current random string, and the current hash value includes: Identify the reference delimiter in the current string; The current string is segmented according to the reference delimiter to obtain the current device information, the current random string, and the current hash value.
3. The method according to claim 1, characterized in that, After recognizing the current string of the device information QR code during the QR code verification phase, the following is also included: Perform length detection and content verification on the current string; If the length or content of the current string fails the length check or fails the content check, the current string will be discarded. Accordingly, the step of segmenting the current string to obtain the current device information, the current random string, and the current hash value includes: When the length and content of the current string pass the length detection and content detection, the current string is split to obtain the current device information, the current random string, and the current hash value.
4. The method according to claim 1, characterized in that, Before recognizing the current string of the device information QR code during the QR code verification phase, the method further includes: During the QR code generation phase, when a QR code generation request is detected, the current device information and a random string from the server are obtained, and a random string is generated. The current device information, the current random string, and the server-side random string are concatenated to obtain a second concatenation result; The target hash algorithm is used to perform hash calculation on the second concatenation result to obtain the current hash value; The current device information, the current random string, and the current hash value are concatenated to obtain a third concatenation result; Based on the third stitching result, a device information QR code is generated.
5. The method according to claim 4, characterized in that, Before obtaining the current device information and server-side random string and randomly generating the current random string when a QR code generation request is detected during the QR code generation stage, the method further includes: During the server-side initialization phase, check if a server-side random string exists; If the server-side random string does not exist, a server-side random string of a preset length will be generated.
6. The method according to claim 4, characterized in that, The concatenation of the current device information, the current random string, and the current hash value to obtain the third concatenation result includes: The current device information, the current random string, the current hash value, and the target hash algorithm identifier are concatenated to obtain a third concatenation result; Accordingly, the step of segmenting the current string to obtain the current device information, the current random string, and the current hash value includes: The current string is segmented to obtain the current device information, the current random string, the current hash value, and the target hash algorithm identifier; Accordingly, the step of employing a target hash algorithm to perform hash calculation on the first concatenation result to obtain a verification hash value includes: Detect the target hash algorithm based on the target hash algorithm identifier; The target hash algorithm is used to perform hash calculation on the first concatenation result to obtain the verification hash value.
7. A QR code verification device, characterized in that, Applied to the server side, the device includes: The device information QR code recognition module is used to recognize the current string of the device information QR code during the QR code verification stage; The current string segmentation module is used to segment the current string to obtain current device information, current random string, and current hash value; The first concatenation result generation module is used to obtain a random string from the server and concatenate the random string from the server, the current device information, and the current random string to obtain a first concatenation result. The verification hash value calculation module is used to perform hash calculation on the first concatenation result using the target hash algorithm to obtain the verification hash value; The device information QR code verification module is used to compare the current hash value and the verification hash value, and determine the target verification result of the device information QR code based on the hash value comparison result.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the QR code verification method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the QR code verification method according to any one of claims 1-6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the QR code verification method according to any one of claims 1-6.