Food traceability two-dimensional code generation method and system

By adopting the QR code generation method in food traceability, combining the traceability encoding rules and AES encryption algorithm, the problem of insufficient information security and encoding accuracy of existing food traceability methods is solved, and the rapid, accurate and safe traceability of food traceability information is achieved, and the efficiency and management level of food traceability are improved.

CN119722102AInactive Publication Date: 2025-03-28安徽伟宏食品有限公司
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411788159.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-03-28
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing food traceability methods have the problem that identification codes are easily copied and forged and difficult to adapt to large-scale applications. In addition, information integrity, security and coding accuracy are insufficient, making it difficult to achieve fast, accurate and safe traceability of food life cycle information.

Method used

Provide a method for generating food traceability QR codes. By collecting food-related information, using formulated traceability encoding rules to generate a complete, unique traceability code with verification and correction capabilities, and encrypting it using AES symmetric encryption algorithm to finally generate a food traceability QR code.

Benefits of technology

It realizes the rapid, accurate and safe storage and transmission of food traceability information, improves the reliability and anti-interference ability of data, supports rapid generation and query, has the characteristics of efficiency, ease of use and scalability, and improves the efficiency and management level of food traceability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119722102A_ABST
    Figure CN119722102A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of food traceability, in particular to a food traceability two-dimensional code generation method and system, and the method comprises the steps: collecting food related information, including production enterprise information, raw material information and food processing information; according to the collected food-related information, combining into a complete and unique traceability code with verification and error correction capability by using a formulated traceability coding rule; after the traceability code is obtained, the traceability code is encrypted by adopting an AES symmetric encryption algorithm; generating a food traceability two-dimensional code according to the encrypted traceability code; and after the two-dimensional code is generated, the user scans the two-dimensional code to enter the food traceability information interface, and different types of user query information have different permissions. According to the method, the food traceability technology is combined with the AES symmetric encryption algorithm, the transmission and storage safety of the food information data is guaranteed while the food information is accurately traced, and accurate, safe and convenient traceability of food traceability is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of food traceability, and in particular to a method and system for generating a food traceability two-dimensional code. Background Art

[0002] With the continuous improvement of product quality and the continuous growth of people's living consumption level, the product traceability system is becoming more and more important. Especially for food traceability, traditional food traceability methods mostly rely on paper records, which have many disadvantages such as easy damage, inconvenient query, and easy tampering of information. How to quickly and accurately trace the source of food has become the focus of most attention. Food production companies are facing a large number of tracking and tracing needs, and it is very important to achieve full traceability of food.

[0003] Existing food traceability methods are usually based on barcode technology, but this technology has problems such as easy copying and forgery of identification codes and difficulty in adapting to large-scale applications. As a convenient and efficient data storage and transmission carrier, QR code has the characteristics of large storage information and strong encryption. Although it has applications in the field of food traceability, most existing technologies have deficiencies in information integrity, security and coding accuracy, making it difficult to achieve rapid, accurate and safe traceability of food information throughout its life cycle. Therefore, a new and complete food traceability QR code generation method and system is urgently needed. Summary of the invention

[0004] In view of the above-mentioned technical deficiencies, the present invention provides a method and system for generating a food traceability QR code.

[0005] The present invention is achieved through the following technical solutions:

[0006] A method for generating a food traceability QR code is provided, the method comprising the following steps:

[0007] Step S10: Collecting food-related information, including production company information, food category information, raw material information and food processing information;

[0008] Step S20: Based on the collected production enterprise information and food category information, a complete, unique and error-correcting traceability code is formed using the established traceability coding rules, which contains a total of 19 digits, including a 4-digit food category code, a 5-digit production enterprise custom unique identification code, an 8-digit production batch code, and a 2-digit check character code generated by a CRC check algorithm;

[0009] Step S30: After obtaining the traceability code, encrypt it using the AES symmetric encryption algorithm;

[0010] Step S40: Generate a food traceability QR code based on the encrypted traceability code;

[0011] Step S50: After the food traceability QR code is generated, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. The user enters the food traceability information query interface by scanning the QR code to query food information;

[0012] The production enterprise information in step S10 includes the enterprise name, enterprise address, unified social credit code and food production license number; the food category information includes food varieties, food specifications and food trademarks; the raw material information includes the precise latitude and longitude coordinates of the raw material origin, soil quality inspection report, water quality inspection report, raw material supplier information, and the type, application amount and application time of pesticides, the name, dosage and application time of veterinary drugs; the food processing information includes the production date, production batch number, environmental data of the production workshop, equipment number of the production link, operator number of the production link and food additive use information;

[0013] In the step S40, a food traceability two-dimensional code is generated according to the encrypted traceability code. The two-dimensional code format adopts the QR code format, and the size of the two-dimensional code is set according to the size of the food packaging. The generated two-dimensional code is a two-dimensional code pattern that can be printed and displayed.

[0014] Preferably, in step S20, the step of generating the check character code by the CRC check algorithm includes:

[0015] Determine the generating polynomial: Select the CRC-16 algorithm as the CRC check algorithm, and select G(x) as the generating polynomial of CRC-16, as shown in formula (1):

[0016] G(x)=x 16 +x 15 +x 2 +1 (1)

[0017] Where x is a formal variable, indicating the position weight of the bit, and its hexadecimal representation is 0x8005;

[0018] Data processing: Divide the 19-bit traceability code into 8-bit bytes to obtain 3 bytes. Fill the high bit of the third byte with 0 to make it a complete byte. Store the obtained three bytes in a byte array as input data for subsequent calculations.

[0019] Initialize CRC register: For the CRC-16 algorithm, initialize a 16-bit CRC register with an initial value of 0xFFFF. This initial value is the starting point of the CRC calculation process. Different initial values ​​will result in different verification results.

[0020] Calculate the CRC checksum: process each byte in the byte array in order, perform an XOR operation on the initial value of the CRC register and the first byte to obtain the new value of the CRC register; when the 15th bit of the new CRC register value is 1, shift the CRC register value left by one bit and perform an XOR operation with the generating polynomial 0x8005; when the 15th bit of the new CRC register value is 0, only shift the CRC register value left by one bit; repeat the above operation for the second and third bytes, and calculate each byte based on the value of the previous CRC register when processing a byte;

[0021] Generate check character: After completing the CRC check code calculation, the 16-bit value in the CRC register is the CRC check code. Convert the 16-bit CRC check code to hexadecimal. When the converted hexadecimal value is less than 0x10, add 0 in front to get a 2-bit check character; when the converted hexadecimal value is greater than or equal to 0x10, directly get a 2-bit check character.

[0022] Preferably, the step of generating a food traceability QR code according to the encrypted traceability code in step S40 includes:

[0023] Data format conversion: convert the encrypted traceability code data format into UTF-8;

[0024] QR code generation algorithm: QR code generation uses the QR code algorithm, and the QR code version is selected based on the amount of stored data and the size of the QR code;

[0025] Set algorithm parameters: After determining the QR code version, set the parameters. QR code includes 4 error correction levels, namely L (7%), M (15%), Q (25%) and H (30%). Select the error correction level according to the actual data; select the digital mode for the encoding mode;

[0026] QR code image generation: According to the selected QR code algorithm and set parameters, the encrypted traceability code is converted into a QR code image using the Python-based qrcode library.

[0027] Preferably, in step S50, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. When the user is a consumer, distributor or regulatory department staff, after scanning the food traceability QR code to enter the food traceability information interface, the consumer has the permission to view food category information and raw material information; the distributor has the permission to view production enterprise information, food category information and raw material information; the regulatory department staff has the permission to view all food-related information.

[0028] In addition, to achieve the above purpose, the present invention also proposes a food traceability two-dimensional code generation system, the food traceability two-dimensional code generation system comprising:

[0029] Food information data acquisition module: used to collect food-related information, including production enterprise information, raw material information and food processing information;

[0030] Food traceability code encoding module: used to combine the collected food-related information into a complete, unique traceability code with verification and error correction capabilities using the established traceability coding rules;

[0031] Food traceability code security encryption module: used to encrypt the traceability code using the AES symmetric encryption algorithm after obtaining it;

[0032] Food traceability QR code generation module: used to generate food traceability QR code based on the encrypted traceability code;

[0033] Food traceability information query module: After the food traceability QR code is generated, the administrator scans the QR code to enter the food traceability information management interface and configures different query information permissions for different types of users. Users scan the QR code to enter the food traceability information query interface to query food information;

[0034] The production enterprise information in the food information data acquisition module includes the enterprise name, enterprise address, unified social credit code, and food production license number; the food category information includes food varieties, food specifications, and food trademarks; the raw material information includes the precise latitude and longitude coordinates of the raw material origin, soil quality inspection report, water quality inspection report, raw material supplier information, and the type, application amount, and application time of pesticides, the name, dosage, and application time of veterinary drugs; the food processing information includes the production date, production batch number, environmental data of the production workshop, equipment number of the production link, operator number of the production link, and food additive use information;

[0035] The food traceability QR code generation module generates a food traceability QR code according to the encrypted traceability code. The QR code format adopts the QR code format, and the size of the QR code is set according to the size of the food packaging. The generated QR code is a QR code pattern that can be printed and displayed.

[0036] In addition, to achieve the above-mentioned purpose, the present invention also proposes a food traceability QR code generation device, which includes: a memory, a processor, and a food traceability QR code generation program stored in the memory and runnable on the processor, wherein the food traceability QR code generation program is a step to implement a food traceability QR code generation method as described above.

[0037] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer program product, which includes a program for generating a food traceability QR code, etc. When the program for generating a food traceability QR code is executed by a processor, a method for generating a food traceability QR code as described above is implemented.

[0038] The advantages and effects of the present invention are:

[0039] The invention proposes a method and system for generating a food traceability QR code, which uses a formulated traceability coding rule combined with an AES symmetric encryption algorithm to accurately and securely store the relevant information of food traceability in the food traceability QR code, and improves the reliability and anti-interference ability of the data through a CRC checksum algorithm. The proposed food traceability QR code generation system supports rapid generation and query, has the characteristics of high efficiency, ease of use and scalability, complies with the requirements of laws and regulations, can enhance consumer trust, is applicable to a variety of application scenarios, different users have different food information viewing permissions, protects some privacy data, and significantly improves the efficiency of food traceability and the management level of food traceability work. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 The present invention is a flow chart of a method for generating a food traceability QR code.

[0042] Figure 2 This is a structural schematic diagram of a food traceability two-dimensional code generation system of the present invention.

[0043] Figure 3 This is a schematic block diagram of the structure of an electronic device for generating a food traceability two-dimensional code according to the present invention. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] The present invention provides a method for generating a food traceability QR code. Figure 1 As shown, the following steps are included:

[0046] Step S10: Collect food-related information, including production company information, food category information, raw material information and food processing information.

[0047] Specifically, the production enterprise information in step S10 includes the enterprise name, enterprise address, unified social credit code and food production license number, etc., to ensure the legitimacy and traceability of the enterprise;

[0048] Food category information includes food varieties (such as fruits, meats and processed foods), specific varieties (such as Fuji apples, pork belly and potato chips), food specifications (such as weight, volume, packaging specifications, etc.) and food trademarks; raw material information includes the precise latitude and longitude coordinates of the raw material origin (latitude and longitude coordinates, which can be obtained through map positioning tools), soil quality inspection report, water source quality inspection report (related inspection agency, inspection time, inspection indicators and results), climate conditions (such as seasonal temperature, precipitation data, etc., refer to local meteorological station records), raw material supplier information, and the type, application amount and application time of pesticides, the name, dosage and application time of veterinary drugs;

[0049] Food processing information includes production date, production batch number, environmental data of the production workshop (such as temperature, humidity, cleanliness index and monitoring time), equipment number of the production link, operator number of the production link and food additive use information (such as additive name, dosage standard, national standard or industry standard number that meets the requirements and supplier qualification information);

[0050] After collecting the above food-related information, it is recommended to establish a food traceability information database for unified viewing and management.

[0051] Step S20: Based on the collected production enterprise information and food category information, a complete, unique traceability code with verification and error correction capabilities is combined using the established traceability coding rules, which contains a total of 19 digits, including a 4-digit food category code, a 5-digit production enterprise custom unique identification code, an 8-digit production batch code, and a 2-digit verification character code generated by a CRC verification algorithm.

[0052] Specifically, the check character code step generated by the CRC check algorithm in step S20 includes:

[0053] Determine the generating polynomial: Select the CRC-16 algorithm as the CRC check algorithm, and select G(x) as the generating polynomial of CRC-16, as shown in formula (1):

[0054] G(x)=x 16 +x 15 +x 2 +1 (1)

[0055] Where x is a formal variable, indicating the position weight of the bit, and its hexadecimal representation is 0x8005;

[0056] Data processing: Divide the 19-bit traceability code into 8-bit bytes to obtain 3 bytes. Fill the high bit of the third byte with 0 to make it a complete byte. Store the obtained three bytes in a byte array as input data for subsequent calculations. For example, assuming the traceability code is S=S 18 S 17 S 16 ...S1S0, divide it into bytes (8 bits per group), and you can get 3 bytes: B0 = (S 18 S 17 …S 11 )2、B1=(S 10 S9…S3)2 and B2=(S2S1S000000)2;

[0057] Initialize CRC register: For the CRC-16 algorithm, initialize a 16-bit CRC register with an initial value of 0xFFFF. This initial value is the starting point of the CRC calculation process. Different initial values ​​will result in different verification results.

[0058] Calculate the CRC checksum: process each byte in the byte array in order, perform an XOR operation on the initial value of the CRC register and the first byte B0 to obtain the new value of the CRC register; when the 15th bit of the new CRC register value is 1, shift the value of the CRC register left by one bit and perform an XOR operation with the generating polynomial 0x8005; when the 15th bit of the new CRC register value is 0, only shift the value of the CRC register left by one bit; repeat the above operation for the second byte B1 and the third byte B2, and calculate each byte based on the value of the previous CRC register when processing it;

[0059] Generate check character: After completing the CRC check code calculation, the 16-bit value in the CRC register is the CRC check code. Convert the 16-bit CRC check code to hexadecimal. When the converted hexadecimal value is less than 0x10, add 0 in front to get a 2-bit check character. For example, if the CRC check code is 0x0C, 0C is the 2-bit check character. When the converted hexadecimal value is greater than or equal to 0x10, directly get a 2-bit check character. For example, if the CRC check code is 0x1A, 1A is the 2-bit check character.

[0060] Step S30: After obtaining the traceability code, encrypt it using the AES symmetric encryption algorithm.

[0061] Specifically, the step of encrypting it using the AES symmetric encryption algorithm in step S30 includes:

[0062] Prepare the key and initialization vector: select a 128-bit, 16-byte security key and prevent it from being leaked; select a random initialization vector with the same length as the key to increase the randomness of the encryption and prevent the same plaintext from generating the same ciphertext in different encryption processes;

[0063] Plain text preparation: converting the 19-digit traceability code generated in step S20 into a byte sequence;

[0064] Plaintext padding: AES encryption requires that the plaintext length be a multiple of 16 bytes. When the plaintext length does not meet the multiple of 16 bytes, the PKCS7 padding method is used for padding;

[0065] Encryption Mode: Select Cipher Block Chaining Mode as the encryption mode;

[0066] Perform encryption: Use the selected key, initialization vector, and encryption mode to call the AES encryption algorithm to encrypt the padded plaintext and generate a byte sequence;

[0067] Sequence conversion: Convert the encrypted byte sequence into a 19-digit traceability code to obtain the encrypted traceability code.

[0068] Step S40: Generate a food traceability QR code based on the encrypted traceability code.

[0069] Specifically, the step of generating a food traceability QR code according to the encrypted traceability code in step S40 includes:

[0070] Data format conversion: convert the encrypted traceability code data format into UTF-8;

[0071] QR code generation algorithm: QR code generation uses the QR code algorithm, and the QR code version is selected based on the amount of stored data and the size of the QR code;

[0072] Set algorithm parameters: After determining the QR code version, set the parameters. QR code includes 4 error correction levels, namely L (7%), M (15%), Q (25%) and H (30%). Select the error correction level according to the actual data; select the digital mode for the encoding mode;

[0073] QR code image generation: According to the selected QR code algorithm and set parameters, the encrypted traceability code is converted into a QR code image using the Python-based qrcode library.

[0074] Step S40: Generate a food traceability QR code based on the encrypted traceability code.

[0075] Specifically, the step of generating a food traceability QR code according to the encrypted traceability code in step S40 includes:

[0076] Data format conversion: convert the encrypted traceability code data format into UTF-8;

[0077] QR code generation algorithm: QR code generation uses the QR code algorithm, and the QR code version is selected based on the amount of stored data and the size of the QR code;

[0078] Set algorithm parameters: After determining the QR code version, set the parameters. QR code includes 4 error correction levels, namely L (7%), M (15%), Q (25%) and H (30%). Select the error correction level according to the actual data; select the digital mode for the encoding mode;

[0079] QR code image generation: According to the selected QR code algorithm and set parameters, the encrypted traceability code is converted into a QR code image using the Python-based qrcode library.

[0080] Step S50: After the food traceability QR code is generated, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. The user enters the food traceability information query interface by scanning the QR code to query food information.

[0081] Specifically, in step S50, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. When the user is a consumer, distributor or regulatory staff, after scanning the food traceability QR code to enter the food traceability information interface, the consumer has the permission to view food category information and raw material information; the distributor has the permission to view production enterprise information, food category information and raw material information; the regulatory staff has the permission to view all food-related information.

[0082] In addition, the present invention also proposes a food traceability QR code generation system, please refer to Figure 2 The food traceability QR code generation system comprises:

[0083] Food information data acquisition module: used to collect food-related information, including production enterprise information, raw material information and food processing information;

[0084] Food traceability code encoding module: used to combine the collected food-related information into a complete, unique traceability code with verification and error correction capabilities using the established traceability coding rules;

[0085] Food traceability code security encryption module: used to encrypt the traceability code using the AES symmetric encryption algorithm after obtaining it;

[0086] Food traceability QR code generation module: used to generate food traceability QR code based on the encrypted traceability code;

[0087] Food traceability information query module: After the food traceability QR code is generated, the administrator scans the QR code to enter the food traceability information management interface and configures different query information permissions for different types of users. Users scan the QR code to enter the food traceability information query interface to query food information;

[0088] The production enterprise information in the food information data acquisition module includes the enterprise name, enterprise address, unified social credit code, and food production license number; the food category information includes food varieties, food specifications, and food trademarks; the raw material information includes the precise latitude and longitude coordinates of the raw material origin, soil quality inspection report, water quality inspection report, raw material supplier information, and the type, application amount, and application time of pesticides, the name, dosage, and application time of veterinary drugs; the food processing information includes the production date, production batch number, environmental data of the production workshop, equipment number of the production link, operator number of the production link, and food additive use information;

[0089] The food traceability QR code generation module generates a food traceability QR code based on the encrypted traceability code. The QR code format adopts the QR code format, and the size of the QR code is set according to the size of the food packaging. The generated QR code is a QR code pattern that can be printed and displayed.

[0090] The food traceability two-dimensional code generation system provided by the present application adopts a food traceability two-dimensional code generation method in the above embodiment, which can solve the technical problems of the traditional food traceability method with little information and poor confidentiality. Compared with the prior art, the beneficial effects of the food traceability two-dimensional code generation system provided by the present application are the same as the beneficial effects of the food traceability two-dimensional code generation method provided by the above embodiment, and the other technical features of the food traceability two-dimensional code generation system are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0091] The present application provides a food traceability QR code generation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a food traceability QR code generation method in the above-mentioned embodiment one.

[0092] Reference below Figure 3, which shows a schematic diagram of the structure of a food traceability two-dimensional code generation device suitable for implementing the embodiment of the present application. A food traceability two-dimensional code generation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The food traceability QR code generation device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0093] Figure 3 The food traceability two-dimensional code generating device shown may include a processing system 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage system 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of a food traceability two-dimensional code generating device are also stored. The processing system 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: an input system 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output system 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage system 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication system 1009. The communication system 1009 can allow a food traceability two-dimensional code generation device to communicate wirelessly or wired with other devices to exchange data. Although a food traceability two-dimensional code generation device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or provided alternatively.

[0094] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication system, or installed from a storage system 1003, or installed from a ROM 1002. When the computer program is executed by the processing system 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0095] The food traceability two-dimensional code generation device provided by the present application adopts a food traceability two-dimensional code generation method in the above embodiment, which can solve the technical problems of the traditional food traceability method with little information and poor confidentiality. Compared with the prior art, the beneficial effects of the food traceability two-dimensional code generation device provided by the present application are the same as the beneficial effects of the food traceability two-dimensional code generation method provided by the above embodiment, and the other technical features of the food traceability two-dimensional code generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0096] The various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0097] The present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the above-mentioned method for generating a food traceability QR code.

[0098] The computer program product provided by this application can solve the technical problems of traditional food traceability methods, such as little information and poor confidentiality. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as those of the method for generating a food traceability QR code provided in the above embodiment, which will not be described in detail here.

[0099] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for generating a food traceability QR code, characterized in that: The method comprises the following steps: Step S10: Collecting food-related information, including production company information, food category information, raw material information and food processing information; Step S20: Based on the collected production enterprise information and food category information, a complete, unique and error-correcting traceability code is formed using the established traceability coding rules, which contains a total of 19 digits, including a 4-digit food category code, a 5-digit production enterprise custom unique identification code, an 8-digit production batch code, and a 2-digit check character code generated by a CRC check algorithm; Step S30: After obtaining the traceability code, encrypt it using the AES symmetric encryption algorithm; Step S40: Generate a food traceability QR code based on the encrypted traceability code; Step S50: After the food traceability QR code is generated, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. The user enters the food traceability information query interface by scanning the QR code to query food information; The production enterprise information in step S10 includes the enterprise name, enterprise address, unified social credit code and food production license number; the food category information includes food varieties, food specifications and food trademarks; the raw material information includes the precise latitude and longitude coordinates of the raw material origin, soil quality inspection report, water quality inspection report, raw material supplier information, and the type, application amount and application time of pesticides, the name, dosage and application time of veterinary drugs; the food processing information includes the production date, production batch number, environmental data of the production workshop, equipment number of the production link, operator number of the production link and food additive use information; In the step S40, a food traceability two-dimensional code is generated according to the encrypted traceability code. The two-dimensional code format adopts the QR code format, and the size of the two-dimensional code is set according to the size of the food packaging. The generated two-dimensional code is a two-dimensional code pattern that can be printed and displayed.

2. A method for generating a food traceability two-dimensional code according to claim 1, characterized in that: In step S20, the step of generating the check character code by the CRC check algorithm includes: Determine the generating polynomial: Select the CRC-16 algorithm as the CRC check algorithm and select G(x) as the generating polynomial of CRC-16, as shown in formula (1): G(x)=x 16 +x 15 +x 2 +1 (1) Where x is a formal variable, indicating the position weight of the bit, and its hexadecimal representation is 0x8005; Data processing: Divide the 19-bit traceability code into 8-bit bytes to obtain 3 bytes. Fill the high bit of the third byte with 0 to make it a complete byte. Store the obtained three bytes in a byte array as input data for subsequent calculations. Initialize CRC register: For the CRC-16 algorithm, initialize a 16-bit CRC register with an initial value of 0xFFFF. This initial value is the starting point of the CRC calculation process. Different initial values ​​will result in different verification results. Calculate the CRC checksum: process each byte in the byte array in order, perform an XOR operation on the initial value of the CRC register and the first byte to obtain the new value of the CRC register; when the 15th bit of the new CRC register value is 1, shift the CRC register value left by one bit and perform an XOR operation with the generating polynomial 0x8005; when the 15th bit of the new CRC register value is 0, only shift the CRC register value left by one bit; repeat the above operation for the second and third bytes, and calculate each byte based on the value of the previous CRC register when processing a byte; Generate check character: After completing the CRC check code calculation, the 16-bit value in the CRC register is the CRC check code. Convert the 16-bit CRC check code to hexadecimal. When the converted hexadecimal value is less than 0x10, add 0 in front to get a 2-bit check character; when the converted hexadecimal value is greater than or equal to 0x10, directly get a 2-bit check character.

3. A method for generating a food traceability two-dimensional code according to claim 1, characterized in that: The step of encrypting the data using the AES symmetric encryption algorithm in step S30 includes: Prepare the key and initialization vector: select a 128-bit, 16-byte security key and prevent it from being leaked; select a random initialization vector with the same length as the key to increase the randomness of the encryption and prevent the same plaintext from generating the same ciphertext in different encryption processes; Plain text preparation: converting the 19-digit traceability code generated in step S20 into a byte sequence; Plaintext padding: AES encryption requires that the plaintext length be a multiple of 16 bytes. When the plaintext length does not meet the multiple of 16 bytes, the PKCS7 padding method is used for padding; Encryption Mode: Select Cipher Block Chaining Mode as the encryption mode; Perform encryption: Use the selected key, initialization vector, and encryption mode to call the AES encryption algorithm to encrypt the padded plaintext and generate a byte sequence; Sequence conversion: Convert the encrypted byte sequence into a 19-digit traceability code to obtain the encrypted traceability code.

4. A method for generating a food traceability QR code according to claim 1, characterized in that: The step of generating a food traceability QR code according to the encrypted traceability code in step S40 includes: Data format conversion: convert the encrypted traceability code data format into UTF-8; QR code generation algorithm: QR code generation uses the QR code algorithm, and the QR code version is selected based on the amount of stored data and the size of the QR code; Set algorithm parameters: After determining the QR code version, set the parameters. QR code includes 4 error correction levels, namely L (7%), M (15%), Q (25%) and H (30%). Select the error correction level according to the actual data; select the digital mode for the encoding mode; QR code image generation: According to the selected QR code algorithm and set parameters, the encrypted traceability code is converted into a QR code image using the Python-based qrcode library.

5. The method for generating a food traceability QR code according to claim 1, characterized in that: In step S50, the administrator enters the food traceability information management interface by scanning the QR code and configures different query information permissions for different types of users. When the user is a consumer, distributor or regulatory department staff, after scanning the food traceability QR code to enter the food traceability information interface, the consumer has the permission to view food category information and raw material information; the distributor has the permission to view production enterprise information, food category information and raw material information; the regulatory department staff has the permission to view all food-related information.

6. A food traceability QR code generation system, characterized in that: The food traceability QR code generation system comprises: Food information data acquisition module: used to collect food-related information, including production enterprise information, raw material information and food processing information; Food traceability code encoding module: used to combine the collected food-related information into a complete, unique traceability code with verification and error correction capabilities using the established traceability coding rules; Food traceability code security encryption module: used to encrypt the traceability code using the AES symmetric encryption algorithm after obtaining it; Food traceability QR code generation module: used to generate food traceability QR code based on the encrypted traceability code; Food traceability information query module: After the food traceability QR code is generated, the administrator scans the QR code to enter the food traceability information management interface and configures different query information permissions for different types of users. Users scan the QR code to enter the food traceability information query interface to query food information; The production enterprise information in the food information data acquisition module includes the enterprise name, enterprise address, unified social credit code, and food production license number; the food category information includes food varieties, food specifications, and food trademarks; the raw material information includes the precise latitude and longitude coordinates of the raw material origin, soil quality inspection report, water quality inspection report, raw material supplier information, and the type, application amount, and application time of pesticides, the name, dosage, and application time of veterinary drugs; the food processing information includes the production date, production batch number, environmental data of the production workshop, equipment number of the production link, operator number of the production link, and food additive use information; The food traceability QR code generation module generates a food traceability QR code according to the encrypted traceability code. The QR code format adopts the QR code format, and the size of the QR code is set according to the size of the food packaging. The generated QR code is a QR code pattern that can be printed and displayed.

7. A food traceability QR code generation device, characterized in that: The food traceability two-dimensional code generation device comprises: A memory, a processor, and a food traceability QR code generation program stored in the memory and executable on the processor, wherein the food traceability QR code generation program, when executed by the processor, implements a food traceability QR code generation method as described in any one of claims 1 to 5.

8. A computer program product, characterized in that The computer program product includes a food traceability two-dimensional code generation program, and when the food traceability two-dimensional code generation program is executed by a processor, it implements a food traceability two-dimensional code generation method as described in any one of claims 1 to 5.

Citation Information

Cited By

  • Card password generation method and device, card password jet printing method and device, card password verification method and device, terminal and storage medium

    CN120910923A

  • Food safety raw material rapid traceability and verification system based on two-dimensional code

    CN121094570A

  • Poultry product traceability management method and system for food safety

    CN122492243A

  • A poultry product traceability management method and system for food safety

    CN122492243B