A method for encrypting and decrypting secondary data of environmental protection equipment communication protocol
By adopting the dual encryption structure of device key and platform key in the communication protocol of environmental protection instruments, combined with SM4 encryption algorithm and CRC16 check, the problem of forgery and tampering in data communication of environmental protection instruments is solved, and the efficiency of data transmission is improved. Security and integrity.
Patent Information
- Application Number
- CN202410888462.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-07-04
AI Technical Summary
Environmental protection instruments can easily forge data communication messages through clear text MN codes and transmission passwords, and simulate on-site instruments to send interference data to the platform, causing system security to be compromised.
Using the secondary data encryption method of the environmental protection equipment communication protocol, by distributing and using the device key and platform key between the environmental protection equipment and the platform, the SM4 encryption algorithm is used to double encrypt the data, and the CRC16 check value is used to ensure data transmission of integrity.
Effectively prevent network attacks and data tampering, ensure the security of communication messages and the authenticity of data, and prevent data leaks and system security from being destroyed.
Smart Images

Figure CN118432949B
Abstract
Description
Technical Field
[0001] The invention relates to a method for encrypting and decrypting secondary data of a communication protocol of an environmental protection device. Background Art
[0002] Environmental protection instruments are the main means of supervision by the national ecological and environmental protection departments on pollutant-emitting enterprises, and their analysis data has the attributes of law enforcement and evidence collection. HJ212-2017 "Data Transmission Standard for Online Pollutant Monitoring (Monitoring) System" (referred to as HJ212-2017 protocol in this invention) is an environmental protection instrument data transmission protocol issued by the Ministry of Ecology and Environment of the People's Republic of China. Figure 4 and Figure 5 As shown, the protocol consists of plain text. When data is communicated through the Internet, the plain text message data is easily obtained by the packet capture software, resulting in data leakage. After the communication data is captured, the plain text MN code and transmission password can be used to easily forge data communication messages, simulate the field instrument to send interference data to the platform, and inject attacks on the HJ212 data field can also destroy the security of the environmental protection data receiving platform database system. It is urgent to solve the problem of online data encryption transmission of environmental protection equipment. Summary of the invention
[0003] The present invention improves the above-mentioned problem, that is, the technical problem to be solved by the present invention is that as the environmental protection instrument passes the plain text MN code and transmission password, it is easy to forge data communication messages, and simulate the field instrument to send interference data to the platform, which may easily endanger the system security.
[0004] The specific implementation scheme of the present invention is: a method for encrypting and decrypting secondary data of an environmental protection equipment communication protocol, the method comprising an environmental protection equipment arranged at a discharge port and a platform for sending and receiving environmental protection equipment information; the method adopts the following data encryption steps:
[0005] S11: Allocate the MN code of the environmental protection equipment according to the location of the discharge port of the environmental protection equipment, and give the equipment an initialization access password. The environmental protection equipment is configured with a platform key;
[0006] S12: The environmental protection equipment reports the instrument key to the platform. The platform generates a key reporting message using the HJ212-2017 protocol extended command format, and encrypts the CP data segment in the key reporting message and reports it to the platform.
[0007] The platform determines whether the instrument key request is in the state of waiting for key allocation according to the MN code and access password of the environmental protection equipment. If not, the instrument key application process is exited; if yes, the platform generates an instrument key;
[0008] S13: The platform generates an instrument key, issues the instrument key ciphertext, and issues the instrument key and platform key to the environmental protection device. After the environmental protection device parses the instrument key ciphertext, it stores the acquired instrument key inside the environmental protection device.
[0009] The environmental protection equipment works and monitors the monitored object, and collects the monitored values to form monitoring values; the environmental protection equipment generates a data message with the MN code, access password, platform key, instrument key and the acquired monitoring values and reports it to the platform;
[0010] The specific steps for encrypting data messages are as follows:
[0011] S21: The environmental protection device performs SM4 encryption on the CP data segment of the HJ212-2017 data message using the instrument key according to the HJ212-2017 protocol structure to obtain a PK1 data encryption message;
[0012] S22: The environmental protection device will use the HJ212-2017 protocol to encapsulate the MN code, access password and PK1 data encryption message to obtain the PK2 data encryption message;
[0013] S23: Use the platform key to perform SM4 secondary encryption on the PK2 data encrypted message to obtain the PK3 data reporting encrypted message;
[0014] S24: using the CRC16 algorithm, calculating the CRC16 checksum of the PK3 data report encrypted message;
[0015] That is, the final data reporting ciphertext is generated;
[0016] After receiving the ciphertext data reported by the environmental protection equipment, the platform will decrypt it. The specific decryption process is as follows:
[0017] S31: Verify the header and tail formats of the received data report ciphertext;
[0018] S32: Separate the PK3 data encryption message and CRC16 check value;
[0019] S33: recalculate the CRC16 checksum of the ciphertext and compare it with the CRC16 checksum in the data report ciphertext. If the calculation result does not match, discard the message; if it matches, continue to use the platform key to decrypt the PK3 data encrypted message to obtain the PK2 data encrypted message;
[0020] S34: Use the HJ212-2017 protocol to parse the PK2 data encrypted message and obtain the PK1 data encrypted message of the CP data segment;
[0021] S35: Obtain the current instrument key in the platform database system according to the MN code and access password in the PK2 data encryption message.
[0022] S36: Use the instrument key to decrypt the PK1 data encryption message through the SM4 algorithm to obtain the actual instrument reporting data.
[0023] Preferably, the data reporting ciphertext is: ##+total PK3 length+PK3{PK2[##+length+ST+QN+MN+PW+CN+Flag+CP(PK1)+CRC16]}+CRC16+ <cr> <lf>;
[0024] The MN in the data report ciphertext is the MN code of the environmental protection equipment, QN is the request code, ST indicates the system code, PW is the access password, CP is the data segment, CN is the command code, the data segment in this message is the PK1 data report encrypted message, CRC16 is the CRC16 check value, and ## is the header format; <cr> <lf>The format is the end of the packet.
[0025] Preferably, the application and issuance process of the instrument key in step S12 specifically includes the following steps:
[0026] S121: The environmental protection device generates a key declaration message according to the HJ212-2017 structure, and the command code CN in the key declaration message is 1080; the CP data segment in the key declaration message is encrypted by SM4 using the platform key to obtain a PK1 encrypted key message; and the CRC16 algorithm is used to calculate the CRC16 check value of the PK1 encrypted key message;
[0027] Generate the final key application message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+CP+Flag+CRC16)+CRC16+ <cr> <lf>;
[0028] Among them, ## is the header format; <cr> <lf>It is the packet tail format; MN is the MN code of the environmental protection equipment, QN is the request code, ST indicates the system code, PW is the access password, CP is the data segment in the key declaration message, CN is the command code, and CRC16 is the CRC16 check value;
[0029] S122: The process of the platform sending instrument keys to environmental protection equipment:
[0030] (1) The platform verifies the header and trailer formats of the received key application message;
[0031] (2) Using the HJ212-2017 protocol, analyze the command code CN=1080 in the message to obtain the device MN code and access password;
[0032] (3) Based on the equipment MN code and access password, check in the platform database system whether the environmental protection equipment configuration status of the current discharge port is in the state of waiting for key allocation. If not, exit the instrument key application process; if so, the platform generates an instrument key and sends it to the environmental protection equipment.
[0033] Preferably, the platform sends the instrument key to the environmental protection equipment instrument key ciphertext in the following steps:
[0034] S41: The platform generates a key-issuing message based on the HJ212-2017 structure, including command direction ST=91, command code CN=1080, platform key and instrument key;
[0035] S42: Use the platform key to perform SM4 encryption on the HJ212-2017 key delivery message to obtain the key delivery PK1 encrypted message;
[0036] S43: Calculate the CRC16 checksum of PK1 using the CRC16 algorithm;
[0037] S44: Generate the final sent message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+Flag+CP+CRC16)+CRC16+ <cr> <lf>;
[0038] S45: After parsing the message, the instrument stores the obtained platform key and instrument key inside the instrument.
[0039] MN in the sent message is the MN code of the environmental protection device, QN is the request code, ST is the system code, PW is the access password, Flag is the split package and response flag, CP is the data segment, CN is the command code, the data segment in this message is the PK1 data report encrypted message, CRC16 is the CRC16 check value, and ## is the packet header format; <cr> <lf>The format is the end of the packet.
[0040] Preferably, the CRC16 check value adopts the ANSICRC16 check method. In the specific check process, the CRC16 check value is calculated by the transmission device and then added to the data packet; the receiving device recalculates the CRC16 check value of the received data packet and compares it with the received CRC16 check value. If the two values are different, there is an error;
[0041] The steps to generate the CRC16 check byte are as follows:
[0042] 1) The CRC16 check register is assigned a value of 0xFFFF;
[0043] 2) Take the first byte of the string to be checked and assign it to the temporary register;
[0044] 3) Perform "XOR" operation on the temporary register and the high byte of the CRC16 check register, and assign the value to the CRC16 check register;
[0045] 4) Take the last bit of the CRC16 check register and assign it to the detection register;
[0046] 5) Shift the CRC16 check register right by one position;
[0047] 6) If the detection register value is 1, the CRC16 check register is XORed with the polynomial 0xA001 and the value is assigned to the CRC16 check register;
[0048] 7) Repeat steps 4 to 6 until 8 bits are shifted out;
[0049] 8) Get the next byte of the string to be checked and assign it to the temporary register;
[0050] 9) Repeat steps 3 to 8 until all bytes of the string to be checked are checked;
[0051] 10) Return the value of the CRC16 check register; the CRC16 check value is stored in the order of high byte first and low byte later.
[0052] Compared with the prior art, the present invention has the following beneficial effects:
[0053] The present invention adds a structure of using a device key to perform SM4 data encryption on the basis of the original communication protocol encapsulation structure of HJ212, and uses a platform key to perform secondary SM4 encryption to complete the data encryption process and improve the security of data reporting and platform information distribution.
[0054] Extended key issuance communication protocol: Based on the HJ212 structure, its function code is extended to enable it to have the function of device key application and issuance.
[0055] The present invention solves the problem of preventing packet capture, and only the ciphertext of the communication message is captured, which effectively blocks network attacks; and solves the problem of data tampering, and after the platform key is obtained, it is still protected by the instrument key.
[0056] In the technology of the present invention, the message is verified by using CRC16 to solve the problem of data transmission distortion caused by the length increase of data after secondary encryption. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a schematic diagram of the working logic structure of the present invention.
[0058] Figure 2 It is a flow chart of the platform key sending message generation of the present invention.
[0059] Figure 3 It is the national secret algorithm GM / T0002 "SM4 block cipher algorithm", the specific encryption / decryption flow chart.
[0060] Figure 4 This is a schematic diagram of the message structure of HJ212-2017 "Data Transmission Standard for Online Pollutant Monitoring (Monitoring) Systems".
[0061] Figure 5 It is the message structure rule of HJ212-2017 "Data Transmission Standard for Online Pollutant Monitoring (Monitoring) Systems".
[0062] Figure 6 It is the encryption protocol structure message of the present invention.
[0063] Figure 7 It is the protocol extension command coding table of HJ212-2017 "Data Transmission Standard for Pollutant Online Monitoring (Monitoring) Systems".
[0064] Figure 8 It is the protocol data segment structure composition table of HJ212-2017 "Data Transmission Standard for Pollutant Online Monitoring (Monitoring) Systems". DETAILED DESCRIPTION
[0065] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0066] like Figures 1 to 7 As shown, the specific implementation scheme of the present invention is: a method for encrypting and decrypting secondary data of an environmental protection equipment communication protocol, characterized in that it includes an environmental protection equipment arranged at a discharge port and a platform for sending and receiving environmental protection equipment information; and includes the following data encryption steps:
[0067] S11: Allocate the MN code of the environmental protection equipment according to the location of the discharge port of the environmental protection equipment, and give the equipment an initialization access password. The environmental protection equipment is configured with a platform key;
[0068] S12: The environmental protection equipment reports the instrument key to the platform. The platform generates a key reporting message using the HJ212-2017 protocol extended command format, and encrypts the CP data segment in the key reporting message and reports it to the platform.
[0069] The platform determines whether the instrument key request is in the state of waiting for key allocation according to the MN code and access password of the environmental protection equipment. If not, the instrument key application process is exited; if yes, the platform generates an instrument key;
[0070] S13: The platform generates an instrument key, issues the instrument key ciphertext, and issues the instrument key and platform key to the environmental protection device. After the environmental protection device parses the instrument key ciphertext, it stores the acquired instrument key inside the environmental protection device.
[0071] The environmental protection equipment works and monitors the monitored object, and collects the monitored values to form monitoring values; the environmental protection equipment generates a data message with the MN code, access password, platform key, instrument key and the acquired monitoring values and reports it to the platform;
[0072] The specific steps for encrypting data messages are as follows:
[0073] S21: The environmental protection device performs SM4 encryption on the CP data segment of the HJ212-2017 data message using the instrument key according to the HJ212-2017 protocol structure to obtain a PK1 data encryption message;
[0074] S22: The environmental protection device will use the HJ212-2017 protocol to encapsulate the MN code, access password and PK1 data encryption message to obtain the PK2 data encryption message;
[0075] S23: Use the platform key to perform SM4 secondary encryption on the PK2 data encrypted message to obtain the PK3 data reporting encrypted message;
[0076] S24: using the CRC16 algorithm, calculating the CRC16 checksum of the PK3 data report encrypted message;
[0077] That is, the final data reporting ciphertext is generated: ##+total PK3 length+PK3{PK2[##+length+ST+QN+MN+PW+CN+Flag+CP(PK1)+CRC16]}+CRC16+ <cr> <lf>;
[0078] The MN in the data reporting ciphertext is the MN code of the environmental protection equipment, QN is the request code, ST represents the system code, PW is the access password, CP is the data segment, and CN is the command code. The data segment in this message is the PK1 data reporting encrypted message, CN is the command code, and CRC16 is the CRC16 check value.
[0079] After receiving the ciphertext data reported by the environmental protection equipment, the platform will decrypt it. The specific decryption process is as follows:
[0080] S31: Verify the header and tail formats of the received data report ciphertext;
[0081] S32: Separate the PK3 data encryption message and CRC16 check value;
[0082] S33: recalculate the CRC16 checksum of the ciphertext and compare it with the CRC16 checksum in the data report ciphertext. If the calculation result does not match, discard the message. If it does match, continue to use the platform key to decrypt the PK3 data encrypted message to obtain the PK2 data encrypted message.
[0083] S34: Use the HJ212-2017 protocol to parse the PK2 data encrypted message and obtain the PK1 data encrypted message of the CP data segment;
[0084] S35: Obtain the current instrument key in the platform database system according to the MN code and access password in the PK2 data encryption message.
[0085] S36: Use the instrument key to decrypt the PK1 data encryption message through the SM4 algorithm to obtain the actual instrument reporting data.
[0086] The SM4 described in the present invention is the national secret algorithm GM / T0002 "SM4 block cipher algorithm", and the specific encryption / decryption flow chart is as shown in the attached Figure 4 The specific SM4 national encryption algorithm is described as follows:
[0087] (1) The input plaintext is 128-bit data, which is split into four 32-bit data x0, x1.
[0088] (2) When i=0, x2 and x3 are transformed in the first round, which continues until i=31.
[0089] (3) xi is not processed for the time being. XOR xi+1, xi+2, xi+3 and the round key rki to obtain a 32-bit data.
[0090] The input of the box transformation is x_input=xi+1⊕xi+2⊕xi+3⊕rki, where the ⊕ symbol represents the XOR operation;
[0091] (4) Split x_input into four 8-bit data, perform box transform on each of them, and then convert the four 8-bit input
[0092] The output is merged into a 32-bit s_output;
[0093] (5) Circularly shift the s_output obtained just now to the left by 2, 10, 18, and 24 bits respectively to obtain four 32-bit
[0094] The result of the shift is y2, y10, y18, y24;
[0095] (6) XOR the shifted results y2, y10, y18, y24 with the box transform output s_output and xi to get xi+4, which is
[0096] xi+4=s_output⊕y2⊕y10⊕y18⊕y24⊕xi
[0097] (7) The first round of encryption and decryption operations is now completed. In the actual encryption and decryption process, the above operations need to be performed 32 rounds.
[0098] Use 32 different RKIs at the same time, RKIs are generated by key expansion;
[0099] (8) Finally, the four generated 32-bit data x35, x34, x33, and x32 are merged into a 128-bit data.
[0100] is the final output result.
[0101] The application and issuance process of the instrument key in step S12 specifically includes the following steps:
[0102] S121: The environmental protection device generates a key declaration message according to the HJ212-2017 structure, and the command code CN in the key declaration message is 1080; the CP data segment in the key declaration message is encrypted by SM4 using the platform key to obtain a PK1 encrypted key message; and the CRC16 algorithm is used to calculate the CRC16 check value of the PK1 encrypted key message;
[0103] Generate the final key application message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+Flag+CP+CRC16)+CRC16+ <cr> <lf>;
[0104] Among them, ## is the header format; <cr> <lf>It is the packet tail format; MN is the MN code of the environmental protection equipment, QN is the request code, ST indicates the system code, PW is the access password, CP is the data segment in the key declaration message, CN is the command code, and CRC16 is the CRC16 check value;
[0105] The interpretation of the data segment structure registration in the present invention can refer to the attached Figure 8 The formats of system codes and command codes are set according to the "System Code Table" and "Command Code Table" in the HJ 212-2017 protocol.
[0106] S122: The process of the platform sending instrument keys to environmental protection equipment:
[0107] (1) The platform verifies the header and trailer formats of the received key application message;
[0108] (2) Using the HJ212-2017 protocol, analyze the command code CN=1080 in the message to obtain the device MN code and access password;
[0109] (3) According to the equipment MN code and access password, check in the platform database system whether the environmental protection equipment configuration status of the current discharge port is in the state of waiting for key allocation. If not, exit the instrument key application process; if so, the platform generates an instrument key and sends it to the environmental protection equipment;
[0110] Preferably, the platform sends the instrument key to the environmental protection equipment instrument key ciphertext in the following steps:
[0111] S41: The platform generates a key-issuing message according to the HJ212-2017 rule structure, including command direction ST=91, command code CN=1080, platform key and instrument key;
[0112] S42: Use the platform key to perform SM4 encryption on the HJ212-2017 key delivery message to obtain the key delivery PK1 encrypted message;
[0113] S43: Calculate the CRC16 checksum of PK1 using the CRC16 algorithm;
[0114] S44: Generate the final sent message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+Flag+CP+CRC16)+CRC16+ <cr> <lf>;
[0115] S45: After parsing the message, the instrument stores the obtained platform key and instrument key inside the instrument.
[0116] MN in the sent message is the MN code of the environmental protection device, QN is the request code, ST is the system code, PW is the access password, Flag is the split package and response flag, CP is the data segment, CN is the command code, the data segment in this message is the PK1 data report encrypted message, CRC16 is the CRC16 check value, and ## is the packet header format; <cr> <lf>The format is the end of the packet.
[0117] The CRC16 check value adopts the ANSICRC16 check method. The specific check process CRC16 check value is calculated by the transmission device and added to the data packet. The receiving device recalculates the CRC16 check value of the received data packet and compares it with the received CRC16 check value. If the two values are different, there is an error.
[0118] The steps to generate the CRC16 check byte are as follows:
[0119] 1) The CRC16 check register is assigned a value of 0xFFFF;
[0120] 2) Take the first byte of the string to be checked and assign it to the temporary register;
[0121] 3) Perform "XOR" operation on the temporary register and the high byte of the CRC16 check register, and assign the value to the CRC16 check register;
[0122] 4) Take the last bit of the CRC16 check register and assign it to the detection register;
[0123] 5) Shift the CRC16 check register right by one position;
[0124] 6) If the detection register value is 1, the CRC16 check register is XORed with the polynomial 0xA001 and the value is assigned to the CRC16 check register;
[0125] 7) Repeat steps 4 to 6 until 8 bits are shifted out;
[0126] 8) Get the next byte of the string to be checked and assign it to the temporary register;
[0127] 9) Repeat steps 3 to 8 until all bytes of the string to be checked are checked;
[0128] 10) Returns the value of the CRC16 check register.
[0129] The CRC16 checksum value is stored in the order of high byte first and low byte later.
[0130] The following uses the water pollution discharge pipeline detection equipment as an example to explain the data encryption and decryption process using the communication protocol designed by the present invention.
[0131] Initial scene data convention:
[0132] Outlet Type: Water Pollution Source
[0133] Testing equipment MN code: 01306849400016F2120011
[0134] Initial access password for the detection device: 123456
[0135] Platform key: 6b73434428236b646d5328262a646473
[0136] Step 1: Application for instrument key for testing equipment:
[0137] Environmental protection equipment generates key declaration message based on HJ212-2017 structure: ##0085QN=20240410085857223;ST=32;CN=1080;PW=123456;MN=013068494000
[0138] 16F2120011;Flag=5;CP=&&&&3240
[0139] The environmental protection device uses the platform key to submit the SM4 encryption key declaration message and obtains the PK1 encryption key message:
[0140] E83371770351250EE47399DFEF926ABDB85DC8F46B64DE31E50A99EB532833F472
[0141] 188D355F32CCB64885DD6AEF0888FD16CB04AD90C9BEE2823BC8D2E72F10BE581C
[0142] DA8A028E78FF82B4C2B6FAF2E902ED02F7ED142F4D2FABF950F9E6A68B4B
[0143] Using the CRC16 algorithm, calculate the CRC16 checksum of PK1 and re-encapsulate the data packet to generate the final key application message:
[0144] ##0192E83371770351250EE47399DFEF926ABDB85DC8F46B64DE31E50A99EB53283
[0145] 3F472188D355F32CCB64885DD6AEF0888FD16CB04AD90C9BEE2823BC8D2E72F10BE
[0146] 581CDA8A028E78FF82B4C2B6FAF2E902ED02F7ED142F4D2FABF950F9E6A68B4BFF0
[0147] 1 <cr> <lf>
[0148] Among them, ## is the header format; <cr> <lf>It is the packet tail format;
[0149] The platform receives the instrument key and sends the following example:
[0150] Step (1): The platform generates a key based on the HJ212-2017 structure and sends the message:
[0151] ##0184QN=20240410085901133;ST=91;CN=1080;PW=123456;MN=013068494000
[0152] 16F2120011;Flag=4;CP=&&Platform Key=6b73434428236b646d5328262a646473&&4F40;
[0153] The instrument key generated by the platform is 732a33393938282a6b736c783d633864, and the access password is 123456;
[0154] Step (1) encrypts the key sending message SM4 with the platform key to form a key sending encrypted message PK1.
[0155] 42491D79E07FD1B6273D68300A6471F24DA20BA4D19AB614E29BB2B741DD2B0D721
[0156] 888D355F32CCB64885DD6AEF0888FD16CB04AD90C9BEE2823BC8D2E72F10BE581CDA
[0157] 8A028E78FF82B4C2B6FAF2E9025681227E917337798D208590620AD1CE8E983C1B1
[0158] C5BAD151B9EAE633DDA47DDCB1D204CE855B6B84F557E5A21348CB5FD3B5501304C
[0159] C60DC777FAE066D8E814CC776EE9142C4553934C49522B8A0FFE71C998BFD725B68
[0160] 7631A288A86F3620786B029923F15E4B46370E0B958D4DB39;
[0161] Step (2) uses the CRC16 algorithm to calculate the CRC16 checksum of PK1, re-encapsulates the data packet, and generates the final message to be sent:
[0162] ##038442491D79E07FD1B6273D68300A6471F24DA20BA4D19AB614E29BB2B741DD
[0163] 2B0D72188D355F32CCB64885DD6AEF0888FD16CB04AD90C9BEE2823BC8D2E72F10
[0164] BE581CDA8A028E78FF82B4C2B6FAF2E9025681227E917337798D208590620AD1CE
[0165] 8E983C1B1C5BAD151B9EAE633DDA47DDCB1D204CE855B6B84F557E5A21348CB5FD
[0166] 3B5501304CC60DC777FAE066D8E814CC776EE9142C4553934C49522B8A0FFE71C9
[0167] 98BFD725B687631A288A86F3620786B029923F15E4B46370E0B958D4DB397800 <C
[0168] R> <lf>.
[0169] Example of data reporting encryption:
[0170] For example, environmental protection equipment collects information and reports pollutant values: chemical oxygen demand 32.56 mg / L, pH 7.13;
[0171] Step (1): Use the instrument key to perform SM4 encryption on the CP data segment of the HJ212-2017 data message to obtain the PK1 data encryption message:
[0172] ##0168QN=20240410085857223;ST=32;CN=2011;PW=123456;MN=013068494000
[0173] 16F2120011;Flag=5;CP=&&DataTime=20240410085857;w01001-Rtd=7.13,w01
[0174] 001-Flag=N;01018-Rtd=32.56,w01018-Flag=N&&FA01;
[0175] Step (2): The environmental protection device will use the HJ212-2017 protocol to encapsulate the MN code, access password and PK1 data encryption message to obtain the PK2 data encryption message:
[0176] ##0277QN=20240410085857223;ST=32;CN=2011;PW=123456;MN=013068494000
[0177] 16F2120011;Flag=5;CP=&&CA0C4677736B8EAF4E503FD0207574ED8DE834E6178
[0178] 02B480D9D7500EFE919DE448DE565400B96F59BC6717AE065E4415A4F0C6C2D142
[0179] E1B5416113116619DB5826799C6E70BAF637078BF9542286EF0B2B2092D821019E
[0180] 246ED9FD59B2289B5&&8701;
[0181] Step (2): Use the platform key to perform SM4 secondary encryption on the PK2 data encrypted message to obtain the PK3 data report encrypted message:
[0182] DC84E230034EDCEE1D3A3F9E7D787948B85DC8F46B64DE31E50A99EB532833F40B
[0183] AFA86346F288C4FAB3904E9C57570316CB04AD90C9BEE2823BC8D2E72F10BE581C
[0184] DA8A028E78FF82B4C2B6FAF2E902A069E9104671892D38C6F4F47CEA8B135179F7
[0185] 0D462D4953937248198E97231F2487976844A46B6DF7D03F3DAB212A7DC85777E4
[0186] 948601BD7C9C0C46190785D81BDFADFC0A4D4EA406FA00C138391A1FFFEBEBC7DD8
[0187] 9AC9B6F1D832A1A159C290FBFF93834EDDE1509E8BF638075AF941A4C73C68E335
[0188] 6F153FCFC1E0F6FCDDA991D68C98DFD14AE4B49D8745CFAF76948E95E14287AD49
[0189] E334D11CECAEB3749254B7B6170148A5B289CFC5648AFF8DDC075713AC2A475449
[0190] 3FE4E5C8F3613D7CC59431C78A68DDDF6B0C381EEE006DBE;
[0191] Step (3): Re-encapsulate the data packet using the CRC16 algorithm, calculate the CRC16 checksum of the PK3 data report encrypted message to generate the final data report ciphertext:
[0192] <h2 style=";text-align:left;direction:ltr">##0576DC84E230034EDCEE1D3A3F9E7D787948B85DC8F46B64DE31E50A99EB5328<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0193] <h2 style=";text-align:left;direction:ltr"> 33F40BAFA86346F288C4FAB3904E9C57570316CB04AD90C9BEE2823BC8D2E72F10<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0194] <h2 style=";text-align:left;direction:ltr"> BE581CDA8A028E78FF82B4C2B6FAF2E902A069E9104671892D38C6F4F47CEA8B13<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0195] <h2 style=";text-align:left;direction:ltr"> 5179F70D462D4953937248198E97231F2487976844A46B6DF7D03F3DAB212A7DC8<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0196] <h2 style=";text-align:left;direction:ltr"> 5777E448601BD7C9C0C46190785D81BDFADFC0A4D4EA406FA00C138391A1FFFEBE<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0197] <h2 style=";text-align:left;direction:ltr"> BC7DD89AC9B6F1D832A1A159C290FBFF93834EDDE1509E8BF638075AF941A4C73C<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0198] <h2 style=";text-align:left;direction:ltr"> 68E3356F153FCFC1E0F6FCDDA991D68C98DFD14AE4B49D8745CFAF76948E95E142<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0199] <h2 style=";text-align:left;direction:ltr"> 87AD49E334D11CECAEB3749254B7B6170148A5B289CFC5648AFF8DDC075713AC2A<h2 style=";text-align:left;direction:ltr"> <h2 style=";text-align:left;direction:ltr">
[0200] <h2 style=";text-align:left;direction:ltr"> 4754493FE4E5C8F3613D7CC59431C78A68DDDF6B0C381EEE006DBEB401<h2 style=";text-align:left;direction:ltr"> <cr> <lf>.
[0201] Unless otherwise stated, any technical solution disclosed in the present invention disclosed above, if it discloses a numerical range, then the disclosed numerical range is a preferred numerical range, and any technician in the field should understand that the preferred numerical range is only a numerical value with a more obvious technical effect or representative value among many implementable numerical values. Since there are too many numerical values to be exhaustive, the present invention discloses some numerical values to illustrate the technical solution of the present invention, and the numerical values listed above should not constitute a limitation on the scope of protection of the present invention.
[0202] If the present invention discloses or involves components or structures that are fixedly connected to each other, then, unless otherwise stated, the fixed connection can be understood as: a detachable fixed connection (for example, connection using bolts or screws), and can also be understood as: a non-detachable fixed connection (for example, riveting, welding). Of course, the mutual fixed connection can also be replaced by an integrated structure (for example, manufactured by one-piece molding using a casting process) (except when it is obviously impossible to use an one-piece molding process).
[0203] In addition, unless otherwise stated, the terms used to indicate positional relationships or shapes in any of the technical solutions disclosed in the present invention include states or shapes that are approximate, similar, or close to them.
[0204] Any component provided by the present invention may be assembled from a plurality of separate components, or may be a separate component manufactured by an integral forming process.
[0205] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, ordinary technicians in the field should understand that the specific implementation methods of the present invention can still be modified or some technical features can be replaced by equivalents without departing from the spirit of the technical solution of the present invention, which should be included in the scope of the technical solution for protection of the present invention.< / lf> < / cr> < / lf> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr> < / lf> < / cr>
Claims
1. A method for encrypting and decrypting secondary data of an environmental protection equipment communication protocol, characterized in that: The method includes an environmental protection device disposed at a discharge port and a platform for sending and receiving information of the environmental protection device; the method adopts the following data encryption steps: S11: Allocate the MN code of the environmental protection equipment according to the location of the discharge port of the environmental protection equipment, and give the equipment an initialization access password. The environmental protection equipment is configured with a platform key; S12: The environmental protection equipment reports the instrument key to the platform. The platform generates a key reporting message based on the HJ212-2017 protocol extended command format, and encrypts the CP data segment in the key reporting message and reports it to the platform. The platform determines whether the instrument key request is in the state of waiting for key allocation according to the MN code and access password of the environmental protection equipment. If not, the instrument key application process is exited; if yes, the platform generates an instrument key; S13: The platform generates an instrument key, issues the instrument key ciphertext, and issues the instrument key and platform key to the environmental protection device. After the environmental protection device parses the instrument key ciphertext, it stores the acquired instrument key inside the environmental protection device. The environmental protection equipment works and monitors the monitored object, and collects the monitored values to form monitoring values; the environmental protection equipment generates a data message with the MN code, access password, platform key, instrument key and the acquired monitoring values and reports it to the platform; The specific steps for encrypting data messages are as follows: S21: The environmental protection device performs SM4 encryption on the CP data segment of the HJ212-2017 data message using the instrument key according to the HJ212-2017 protocol structure to obtain a PK1 data encryption message; S22: The environmental protection device will use the HJ212-2017 protocol to encapsulate the MN code, access password and PK1 data encryption message to obtain the PK2 data encryption message; S23: Use the platform key to perform SM4 secondary encryption on the PK2 data encrypted message to obtain the PK3 data reporting encrypted message; S24: using the CRC16 algorithm, calculating the CRC16 checksum of the PK3 data report encrypted message; That is, the final data reporting ciphertext is generated: After receiving the ciphertext data reported by the environmental protection equipment, the platform will decrypt it. The specific decryption process is as follows: S31: Verify the header and tail formats of the received data report ciphertext; S32: Separate the PK3 data encryption message and CRC16 check value; S33: recalculate the CRC16 checksum of the ciphertext and compare it with the CRC16 checksum in the data report ciphertext. If the calculation result does not match, discard the message; if it matches, continue to use the platform key to decrypt the PK3 data encrypted message to obtain the PK2 data encrypted message; S34: Use the HJ212-2017 protocol to parse the PK2 data encrypted message and obtain the PK1 data encrypted message of the CP data segment; S35: Obtain the current instrument key in the platform database system according to the MN code and access password in the PK2 data encryption message. S36: Use the instrument key to decrypt the PK1 data encryption message through the SM4 algorithm to obtain the actual instrument reporting data; The data reporting ciphertext is: ##+total PK3 length+PK3{PK2[##+length+ST+QN+MN+PW+CN+Flag+CP(PK1)+CRC16]}+CRC16+ <cr> <lf> ;< / lf> < / cr> MN in the data report ciphertext is the MN code of the environmental protection equipment, QN is the request code, ST is the system code, PW is the access password, Flag is the split package and response flag, CP is the data segment, CN is the command code, the data segment in this message is the PK1 data report encrypted message, CRC16 is the CRC16 check value, and ## is the packet header format; <cr> <lf> It is the packet tail format;< / lf> < / cr> The application and issuance process of the instrument key in step S12 specifically includes the following steps: S121: The environmental protection device generates a key declaration message according to the HJ212-2017 structure, and the command code CN in the key declaration message is 1080; the CP data segment in the key declaration message is encrypted by SM4 using the platform key to obtain a PK1 encrypted key message; and the CRC16 algorithm is used to calculate the CRC16 check value of the PK1 encrypted key message; Generate the final key application message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+Flag+CP+CRC16)+CRC16+ <cr> <lf> ;< / lf> < / cr> Among them, ## is the header format; <cr> <lf> It is the packet tail format; MN is the MN code of the environmental protection equipment, QN is the request code, ST is the system code, PW is the access password, Flag is the split package and response flag, CP is the data segment in the key declaration message, CN is the command code, and CRC16 is the CRC16 check value;< / lf> < / cr> S122: The process of the platform sending instrument keys to environmental protection equipment: (1) The platform verifies the header and trailer formats of the received key application message; (2) Using the HJ212-2017 protocol, analyze the command code CN=1080 in the message to obtain the device MN code and access password; (3) According to the equipment MN code and access password, check in the platform database system whether the environmental protection equipment configuration status of the current discharge port is in the state of waiting for key allocation. If not, exit the instrument key application process; if so, the platform generates an instrument key and sends it to the environmental protection equipment; The steps for the platform to send the instrument key to the environmental protection equipment instrument key ciphertext are as follows: S41: The platform generates a key-issuing message based on the HJ212-2017 structure, including command direction ST=91, command code CN=1080, platform key and instrument key; S42: Use the platform key to perform SM4 encryption on the HJ212-2017 key delivery message to obtain the key delivery PK1 encrypted message; S43: Calculate the CRC16 checksum of PK1 using the CRC16 algorithm; S44: Generate the final sent message: ##+total PK1 length+PK1(##+length+ST+QN+MN+PW+CN+Flag+CP+CRC16)+CRC16+ <cr> <lf> ;< / lf> < / cr> S45: After parsing the message, the instrument stores the obtained platform key and instrument key inside the instrument; MN in the sent message is the MN code of the environmental protection device, QN is the request code, ST is the system code, PW is the access password, Flag is the split package and response flag, CP is the data segment, CN is the command code, the data segment in this message is the PK1 data report encrypted message, CRC16 is the CRC16 check value, and ## is the packet header format; <cr> <lf> The format is the end of the packet.< / lf> < / cr> 2. The method for encrypting and decrypting secondary data of an environmental protection equipment communication protocol according to claim 1, characterized in that: The CRC16 check value adopts the ANSICRC16 check method. In the specific check process, the CRC16 check value is calculated by the transmission device and added to the data packet; the receiving device recalculates the CRC16 check value of the received data packet and compares it with the received CRC16 check value. If the two values are different, there is an error; The steps to generate the CRC16 check byte are as follows: 1) The CRC16 check register is assigned a value of 0xFFFF; 2) Take the first byte of the string to be checked and assign it to the temporary register; 3) Perform "XOR" operation on the temporary register and the high byte of the CRC16 check register, and assign the value to the CRC16 check register; 4) Take the last bit of the CRC16 check register and assign it to the detection register; 5) Shift the CRC16 check register right by one position; 6) If the detection register value is 1, the CRC16 check register is XORed with the polynomial 0xA001 and the value is assigned to the CRC16 check register; 7) Repeat steps 4 to 6 until 8 bits are shifted out; 8) Get the next byte of the string to be checked and assign it to the temporary register; 9) Repeat steps 3 to 8 until all bytes of the string to be checked are checked; 10) Return the value of the CRC16 check register; the CRC16 check value is stored in the order of high byte first and low byte later.
