QR code generation, recognition method and electronic device

By adding timestamps and serial numbers to QR codes and adopting scrolling display and recognition methods, the problem of easy duplication of QR codes is solved, and the security and anti-counterfeiting capabilities of QR codes are improved.

CN113792309BActive Publication Date: 2025-09-16ZHUHAI ANCHOR ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111009705.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-31
Publication Date
2025-09-16
Estimated Expiration
2041-08-31

AI Technical Summary

Technical Problem

Existing QR codes are easily copied and forwarded, leading to security issues, especially in high-security situations.

Method used

By adding a timestamp and serial number to the QR code and using a scrolling display and recognition method, the QR code is generated and recognized to improve security.

Benefits of technology

It effectively prevents the copying and forwarding of QR codes, improves the security of QR codes and enhances the anti-counterfeiting capability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113792309B_ABST
    Figure CN113792309B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for generating and identifying a QR code, and an electronic device. The QR code generation method includes the following steps: S1, initializing a sequence number to 0; S2, obtaining actual valid data to be transmitted by a user as user data, and obtaining the current time as a timestamp; S3, combining the user data, the timestamp, and the sequence number to obtain an original string; encrypting and encoding the original string to obtain an encrypted string; S4, displaying the encrypted string using a QR code algorithm; and S5, after a preset time interval, incrementing the sequence number by 1 and returning to step S2. The present invention improves the security of QR code use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a two-dimensional code generation and recognition method and electronic equipment. Background Art

[0002] Currently, the use of QR codes has become an indispensable part of people's daily lives. However, there are major security flaws in the application of QR codes, which are mainly reflected in the problem that QR codes are easily copied and forwarded. Once the QR code is leaked intentionally or unintentionally, it is bound to cause loss of property or safety, causing a major impact on the application of QR codes in higher-security situations.

[0003] The current mainstream technology to prevent the QR code from being copied usually adopts the following methods:

[0004] 1. Time window limitation: set an validity period for each QR code (common ones include WeChat and Alipay). In order to prevent the time difference between the QR code generating device (such as a mobile phone) and the QR code recognition device, the time window is usually more than 2 minutes. The QR code validity period of some offline recognition devices can reach more than 10 minutes, which provides more time for copying and forwarding.

[0005] 2. Mobile software screenshot prevention: For example, WeChat and Alipay payment codes are not allowed to be screenshotted. This prevents third-party software from obtaining and forwarding the payment code through screenshots. However, this solution only prevents the internal software of the mobile phone from copying the QR code; it cannot prevent external methods such as taking a photo and forwarding the QR code. Summary of the Invention

[0006] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention provides a method for generating a two-dimensional code, which can improve the security of the use of the two-dimensional code.

[0007] The present invention also provides an electronic device for generating a two-dimensional code.

[0008] The present invention also provides a two-dimensional code recognition method.

[0009] The present invention also provides an electronic device for recognizing a two-dimensional code.

[0010] According to the first aspect of the present invention, the QR code generation method includes the following steps: S1, initializing the serial number to 0; S2, obtaining the actual valid data to be transmitted by the user as user data, and obtaining the current time as the timestamp; S3, combining the user data, the timestamp and the serial number to obtain the original string; and encrypting and encoding the original string to obtain an encrypted string; S4, displaying the encrypted string through a QR code algorithm; S5, after a preset time interval, increasing the serial number by 1 and returning to step S2.

[0011] The QR code generation method according to the embodiment of the present invention has at least the following beneficial effects: the QR code generation method according to the embodiment of the present invention improves the security of QR code use by adding a timestamp and serial number to the QR code and using a scrolling display and identification method for the QR code, thereby preventing security issues caused by copying and forwarding the QR code.

[0012] According to some embodiments of the present invention, the serial number 16 is an unsigned number ranging from 0 to 65535, and when it exceeds 65535, it automatically continues to cycle from 0.

[0013] According to some embodiments of the present invention, encrypting and encoding the original string includes: performing RSA encryption on the original string using a public key, and then performing BASE64 encoding after encryption. According to some embodiments of the present invention, the preset time interval is 0.3 to 2 seconds, and the QR code generated by the method is scrolled and displayed.

[0014] According to some embodiments of the present invention, the method further includes: generating a QR code with a continuous serial number from the encrypted string.

[0015] According to some embodiments of the present invention, the method further includes: continuously scrolling and displaying the generated sequentially numbered QR codes within a short period of time to generate a changing QR code graphic.

[0016] According to some embodiments of the present invention, the method further includes: the above-mentioned scrolling QR code has a scrolling display interval of 0.3 to 2 seconds, depending on the computing power of the generating device and the identifying device, so as to increase the difficulty for a counterfeiter to forge the scrolling QR code by manually switching the QR code graphics within this shorter time.

[0017] According to the second aspect of the present invention, an electronic device for generating a two-dimensional code includes: a processor for calculating and generating a two-dimensional code graphic; a memory for storing one or more programs; a display for displaying the generated two-dimensional code; and the one or more programs, when executed by the processor, implement any one of the methods in the first aspect of the present invention.

[0018] Since the memory of the electronic device for generating a QR code in the embodiment of the present invention stores one or more programs for executing the QR code generation method as described in any one of the first aspects of the present invention, it has all the beneficial effects of the first aspect of the present invention.

[0019] According to the third aspect of the present invention, the two-dimensional code recognition method is used to identify the two-dimensional code generated by the electronic device according to the second aspect of the present invention, including the following steps: obtaining multiple two-dimensional codes displayed continuously, and obtaining the serial number and timestamp information in each two-dimensional code after decoding and decryption; setting a valid count value; obtaining the interval time of each two-dimensional code according to the timestamp, and judging whether the single two-dimensional code is valid in turn. If the two-dimensional code is invalid, the valid count value is cleared to 0; if the two-dimensional code is valid, judging whether the serial number of the single two-dimensional code obtained this time is the serial number of the previous two-dimensional code plus 1. If so, the valid count value is increased by 1; if not, the valid count value is set to 1 (indicating that this is the first valid two-dimensional code, and the previously recognized two-dimensional code has been invalidated); if the valid count value exceeds the preset value (the preset value can be 2 or 3), the two-dimensional code recognition is completed and the validity of the two-dimensional code and additional user information are returned.

[0020] The QR code recognition method according to the embodiment of the present invention has at least the following beneficial effects: the QR code recognition method according to the embodiment of the present invention improves the security of QR code use by continuously identifying multiple QR codes and judging the correlation between multiple QR codes based on their serial numbers, thereby preventing security problems caused by copying and forwarding of QR codes.

[0021] According to some embodiments of the present invention, determining whether a single QR code is valid includes: obtaining a timestamp corresponding to the QR code, comparing it with the timestamp of the device itself, and obtaining an error between the timestamp of the QR code and the timestamp of the device itself; if the error between the timestamp of the QR code and the timestamp of the device itself is within a preset time error range, the QR code is valid; for devices with an online time calibration function, the preset time error is plus or minus 20 to 60 seconds; for offline recognition devices without a time calibration function, the preset time error is between 5 and 20 minutes. If the error between the timestamp of the QR code and the timestamp of the device itself is within this range, the QR code is considered valid.

[0022] According to some embodiments of the present invention, after the decoding and decryption, the serial number and timestamp information in each QR code are obtained, including: the QR code is identified to obtain an encrypted string, and then decoded through BAS64 to obtain RSA encrypted data, and the RSA encrypted data is decrypted through the RSA private key to obtain a decoded string, and the decrypted string includes the serial number, timestamp and original user data.

[0023] According to some embodiments of the present invention, when continuously acquiring QR codes, it is determined whether the interval time between the QR codes exceeds a preset time (the preset time is in the range of 0.3 to 2 seconds based on the performance of the QR code generating device and the recognition device). If no subsequent QR code is recognized within the preset time, the valid count value is reset to 0.

[0024] According to some embodiments of the present invention, the method also includes: as long as the serial numbers of the QR codes obtained continuously are continuous, they are considered valid, and the effective count value of the recognition is increased by 1. When the effective count value reaches a preset value (the preset value is 2 or 3), the QR code recognition is completed and the original information transmitted by the QR code user is returned.

[0025] According to an embodiment of the fourth aspect of the present invention, an electronic device for recognizing a QR code includes: a processor for parsing and decrypting a QR code graphic; a memory for storing one or more programs; a camera for acquiring a QR code image; and the one or more programs, when executed by the processor, implement any one of the methods in the embodiment of the third aspect of the present invention.

[0026] Since the memory of the electronic device for recognizing a QR code in the embodiment of the present invention stores one or more programs for executing the QR code recognition method as described in any one of the third aspects of the present invention, it has all the beneficial effects of the third aspect of the present invention.

[0027] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned by practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments with reference to the accompanying drawings, in which:

[0029] Figure 1 Schematic diagram of the process of generating a QR code according to an embodiment of the present invention.

[0030] Figure 2 This is a schematic block diagram of modules of an electronic device for generating a QR code according to an embodiment of the present invention.

[0031] Figure 3 Schematic diagram of the flow of the QR code recognition method according to an embodiment of the present invention.

[0032] Figure 4 This is a schematic block diagram of modules of an electronic device for recognizing a QR code according to an embodiment of the present invention.

[0033] Figure 5 Schematic diagram of the process of generating and recognizing a QR code according to an embodiment of the present invention.

[0034] Reference numerals:

[0035] An electronic device 100 for generating a QR code, a processor 101, a memory 102, a display 103, and an electronic device 200 for recognizing a QR code, a processor 201, a memory 202, and a camera 203. DETAILED DESCRIPTION

[0036] The following describes embodiments of the present invention in detail. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended only to explain the present invention and are not to be construed as limiting the present invention.

[0037] In the description of the present invention, "several" means one or more, "more" means two or more, "greater than," "less than," and "exceed" are understood to exclude the number itself, while "above," "below," and "within" are understood to include the number itself. The use of "first" and "second" in the description is solely for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance, implicitly specifying the number of the indicated technical features, or implicitly specifying the order of the indicated technical features.

[0038] In the description of the present invention, step numbers are merely identifications made for the convenience of description or reference, and should not be understood as limiting the operating sequence of the steps.

[0039] In order to solve the problem that QR codes are easily copied and forwarded during use, the embodiments of the present invention provide a supplement to the security use of QR codes to improve the security of QR code use.

[0040] Reference Figure 1 The specific implementation steps of the QR code generation method of the embodiment of the present invention are as follows:

[0041] 1. Initialize the sequence number to 0;

[0042] 2. Obtain the actual valid data that the user wants to transmit as user data, and obtain the current time as the timestamp;

[0043] 3. Combine the user data, timestamp, and sequence number to get the original string;

[0044] 4. Encrypt and encode the original string to obtain the encrypted string.

[0045] 5. Display the encrypted string through the QR code algorithm;

[0046] 6. After a small preset time interval, the serial number is increased by 1 and returns to step 2. The above steps 2 to 5 are repeated to generate a QR code, which becomes a rolling QR code.

[0047] In this embodiment, in addition to the user's own valid data, each QR code needs to be accompanied by a QR code serial number as a basis for QR code relevance identification. Each QR code also needs to be timestamped, which serves as the basis for the QR code recognition device to determine the validity of the QR code. In this embodiment, the string can be displayed using a mainstream QR code algorithm (such as QRCODE) for the QR code recognition device to identify.

[0048] In this embodiment, by adding a timestamp and anti-screenshot method to the scrolling QR code, it is generally difficult to manually switch the display of several related groups of QR codes within the time limit of the rules through copying and forwarding, thereby effectively enhancing the security of the QR code.

[0049] In some embodiments, the sequence number 16 is an unsigned number ranging from 0 to 65535, and automatically continues to cycle from 0 when it exceeds 65535.

[0050] In some embodiments, the timestamp precision is to the second.

[0051] In some embodiments, after valid data, a serial number, and a timestamp are combined, the data is RSA-encrypted using a public key, and the encrypted data is then BASE64-encoded to generate a BASE64-encrypted string. In offline recognition, to enhance the security of the QR code and prevent potential security risks from being cracked, the data used to generate the rolling QR code is RSA-encrypted and then converted into a BASE64 string for display, thus enhancing the security of the algorithm.

[0052] In some embodiments, the scrolling QR code has an interval of 0.3 to 2 seconds, depending on the computing power of the generating device and the identifying device. This shorter time increases the difficulty for a counterfeiter to forge the scrolling QR code by manually switching the QR code graphics.

[0053] Reference Figure 5 In a specific embodiment, the QR code generation method of the embodiment of the present invention includes:

[0054] (1) Obtaining the actual valid data that the user wants to transmit as user data;

[0055] (2) Combine the user data, timestamp (current time), and sequence number to obtain the original string;

[0056] (3) Encrypt the original string with RSA using the public key

[0057] (4) Perform BASE64 encoding on the encrypted data and finally generate a BASE64 encrypted string

[0058] (5) Generate a QR code graphic from the encrypted string using a QR code algorithm and display it;

[0059] (6) Wait for 0.5 to 2 seconds, increase the sequence number by 1, return and repeat the above step (2).

[0060] Reference Figure 2 The electronic device 100 for generating a two-dimensional code according to an embodiment of the present invention includes: a processor 101 for calculating and generating a two-dimensional code graphic; a memory 102 for storing one or more programs; a display 103 for displaying a two-dimensional code graphic; when the one or more programs are executed by the processor 101, the two-dimensional code generation method of the above embodiment is implemented.

[0061] Reference Figure 3 The QR code recognition method of an embodiment of the present invention includes the following steps: obtaining multiple consecutively displayed QR codes, each generated by the aforementioned QR code generation method and complying with the QR code generation rules of the aforementioned QR code generation method; obtaining the sequence number and timestamp information of each QR code through decoding and decryption. Based on the interval between each QR code obtained by the timestamp, the validity of the currently obtained single QR code is determined. If the QR code is invalid, the validity count is reset to 0. If the currently obtained QR code is valid, the sequence number is determined to be the sequence number of the previous QR code plus 1, and the validity count is incremented by 1. Otherwise, the validity count is set to 1 (indicating that this is the first valid QR code and the previously recognized QR code has been invalidated). If the cumulative validity count exceeds a preset value (preset value is 2 or 3), the QR code recognition is terminated and the validity of the QR code and additional user information are returned. In this embodiment, it is necessary to determine whether the sequence numbers are continuous; discontinuous data is considered invalid data. The currently recognized sequence number is then treated as the first sequence number and used as the basis for determining whether the sequence number of the next QR code is continuous. When two or three valid QR codes with consecutive serial numbers are recognized continuously, the QR code recognized this time is considered valid.

[0062] In some embodiments, determining whether a single QR code is valid includes: obtaining the timestamp corresponding to the QR code, comparing it with the timestamp of the device itself, and obtaining the error between the timestamp of the QR code and the timestamp of the device itself; if the error between the timestamp of the QR code and the timestamp of the device itself is within a preset time error range, the QR code is valid.

[0063] In some embodiments, for devices with online time synchronization, the preset time error is plus or minus 20 to 60 seconds; for offline recognition devices without time synchronization, the preset time error is 5 to 20 minutes. The preset time interval depends on the acceptable time error.

[0064] In some embodiments, after decoding and decryption, the serial number and timestamp information in each QR code are obtained, including: the QR code is recognized to obtain an encrypted string, which is then decoded through BAS64 to obtain RSA encrypted data, and the RSA encrypted data is decrypted through the RSA private key to obtain a decoded string, and the decrypted string includes the serial number, timestamp and original user data.

[0065] In some embodiments, when acquiring QR codes continuously, it is determined whether the interval between QR codes exceeds a preset time. If no subsequent QR codes are recognized after the preset time, the valid count value is reset to 0. In this embodiment, according to the agreed time for generating QR code conversion (0.5 to 2 seconds), two or more valid QR codes must be recognized continuously within the time window. If the agreed time is exceeded, the QR code is considered invalid, the recognition count is reset to 0, and recognition is restarted to prevent manual switching of QR code images for cheating.

[0066] Reference Figure 5 In a specific embodiment, the two-dimensional code recognition method of the embodiment of the present invention includes the following steps:

[0067] (1) Initialize and prepare to recognize the QR code;

[0068] (2) Identify the QR code and start timing. If the QR code is not identified within the specified time, the counter is cleared and the process returns to (1).

[0069] (3) If the QR code is recognized within the specified time interval, BAS64 decoding is performed. If it fails, the counter is cleared and the process returns to (2).

[0070] (4) If BAS64 decoding is successful, RSA private key decryption is performed. If it fails, the counter is cleared and the process returns to (2).

[0071] (5) If decryption is successful, each QR code is checked for validity based on the timestamp. If invalid, the counter is reset and the process returns to (2).

[0072] (6) If valid, the counter increases by 1;

[0073] (7) Save the QR code recognition time and determine whether the next QR code is valid until all QR codes are valid;

[0074] (8) Determine whether the counter is greater than 1. If not, clear the counter and return to (2);

[0075] (9) If the counter is greater than 1, determine whether the serial numbers of the multiple recognized QR codes are continuous. If they are continuous, the recognition is successful. If they are not continuous, set the counter to 1 and return to (2).

[0076] The embodiment of the present invention uses a rolling method to continuously generate QR codes to prevent the problem of a single static QR code being easily copied. Specifically, the method uses an algorithm to generate continuously related QR codes. Depending on the recognition speed of the device, each QR code is only displayed for 0.5 to 3 seconds. The recognition device needs to continuously identify 2 to 3 related QR codes within the effective display time of the QR code. The correlation algorithm determines that it is valid. If the recognition device also recognizes two related QR codes in succession, but if the time when the two related QR codes appear is not right, for example, the interval exceeds the expected time, the QR code is also considered to be a copy and is invalid.

[0077] Reference Figure 4 The electronic device 200 for recognizing a two-dimensional code according to an embodiment of the present invention includes: a processor 201 for parsing and decrypting a two-dimensional code graphic; a memory 202 for storing one or more programs; a camera 203 for acquiring two-dimensional code image information; and when one or more programs are executed by the processor 201, the two-dimensional code recognition method according to the above embodiment is implemented.

[0078] It should be appreciated that the method steps in the embodiments of the present invention can be implemented or executed by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer-readable memory. The method can use standard programming techniques. Each program can be implemented in a high-level procedural or object-oriented programming language to communicate with the computer system. However, if desired, the program can be implemented in assembly or machine language. In any case, the language can be a compiled or interpreted language. In addition, for this purpose, the program can be run on a programmed application-specific integrated circuit.

[0079] Furthermore, the operations of the processes described herein may be performed in any suitable order unless otherwise indicated herein or otherwise clearly contradicted by the context. The processes described herein (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions and may be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) that is executed collectively on one or more microprocessors, by hardware, or a combination thereof. The computer program includes a plurality of instructions that can be executed by one or more microprocessors.

[0080] Further, the methods can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Various aspects of the present invention can be implemented as machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, RAM, ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the processes described herein. In addition, the machine-readable code, or portions thereof, can be transmitted over a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described herein includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques of the present invention, the present invention also includes the computer itself.

[0081] The computer program can be applied to input data to perform the functions described herein, thereby converting the input data to generate output data that is stored in a non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the converted data represents a physical and tangible object, including a specific visual depiction of the physical and tangible object produced on the display.

[0082] The embodiments of the present invention are described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Various changes can be made within the knowledge of ordinary technicians in the relevant technical field without departing from the scope of the present invention.

Claims

1. A two-dimensional code recognition method, characterized in that: The method for identifying a QR code generated by an electronic device includes the following steps: Obtain multiple QR codes displayed continuously, and obtain the serial number and timestamp information in each QR code through decoding and decryption; Set the effective count value; The interval time of each QR code is obtained according to the timestamp, and whether a single QR code is valid is determined in turn. If the QR code is invalid, the valid count value is cleared to 0; If the QR code is valid, determine whether the serial number of the single QR code obtained this time is the serial number of the previous QR code plus 1. If so, increase the valid count value by 1; if not, set the valid count value to 1; If the valid count value exceeds the preset value, the QR code recognition is completed and the QR code is valid and additional user information is returned; Determining whether a single QR code is valid includes: The timestamp corresponding to the obtained QR code is compared with the timestamp of the device itself to obtain the error between the timestamp of the QR code and the timestamp of the device itself; If the error between the timestamp of the QR code and the timestamp of the device itself is within the preset time error range, the QR code is valid; For devices with online time synchronization function, the preset time error is plus or minus 20 to 60 seconds; for offline recognition devices without time synchronization function, the preset time error is 5 to 20 minutes; When acquiring QR codes continuously, determine whether the interval between QR codes exceeds a preset time, which is 0.3 to 2 seconds. If no subsequent QR codes are recognized within the preset time, the valid count value is reset to 0. According to the agreed time for generating QR code conversion, more than 3 valid QR codes must be recognized continuously within the time window, and the preset value of the valid count value is 3. If the agreed time is exceeded, the QR code is considered invalid, the recognition count is reset to 0, and recognition is restarted. The QR code is obtained by the following steps: S1, the initialization sequence number is 0; S2. Obtain the actual valid data to be transmitted by the user as user data, and obtain the current time as a timestamp; S3. Combining the user data, the timestamp, and the serial number to obtain an original string; and encrypting and encoding the original string to obtain an encrypted string; S4, scrolling and displaying the encrypted string using a QR code algorithm; S5. After a preset time interval, the sequence number is increased by 1 and the process returns to step S2.

2. The two-dimensional code recognition method according to claim 1, characterized in that: After decoding and decryption, the serial number and timestamp information obtained in each QR code include: The encrypted string is obtained by QR code recognition, and then decoded by BAS64 to obtain RSA encrypted data. The RSA encrypted data is decrypted by the RSA private key to obtain a decrypted string. The decrypted string includes a serial number, a timestamp, and the original user data.

3. The two-dimensional code recognition method according to claim 1, characterized in that: The serial number is a 16-bit unsigned number ranging from 0 to 65535. If it exceeds 65535, it will automatically continue to cycle from 0.

4. The two-dimensional code recognition method according to claim 1, characterized in that: The encrypting and encoding the original character string includes: performing RSA encryption on the original character string using a public key, and performing BASE64 encoding after encryption.

5. An electronic device for recognizing a QR code, characterized in that: include: A processor for parsing and decrypting the QR code graphic; a memory for storing one or more programs; A camera, used to obtain QR code image information; When the one or more programs are executed by the processor, the method of any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Unlocking method and device and storage medium,

    CN110718004A

  • Dynamic two-dimensional code generation method and device and storage medium

    CN110766831A