Encryption Method and Device for Modbus RTU Messages

The AES encryption method for Modbus RTU messages optimizes encryption by extracting data bits from existing message bytes, addressing inefficiencies and enhancing security without expanding message size.

CN115987487BActive Publication Date: 2025-07-15CHINA ENERGY ENG GRP GUANGXI ELECTRIC POWER DESIGN INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211654582.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-22
Publication Date
2025-07-15
Estimated Expiration
2042-12-22

AI Technical Summary

Technical Problem

The existing Modbus RTU packets lack effective encryption methods, making it difficult to achieve efficient and secure information transmission in the power Internet of Things.

Method used

The AES encryption algorithm is used to encrypt the Modbus RTU message. By extracting bit data from the middle position of each byte of the message to both sides until the data bit length required for AES encryption is reached, and encryption is performed to replace the in-situ data.

Benefits of technology

It improves encryption efficiency and security, reduces the computing volume of AES encryption algorithm, and ensures the security and consistency of packets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115987487B_ABST
    Figure CN115987487B_ABST
Patent Text Reader

Abstract

The present invention provides a method and apparatus for encrypting Modbus RTU messages. The current Advanced Encryption Standard (AES) encryption algorithm is used to encrypt Modbus RTU messages. Since the AES encryption algorithm requires encrypting specific data bit lengths during encryption, instead of expanding the Modbus RTU message to have the same number of bytes as the data bit length required by the AES encryption algorithm during encryption and then extracting bit data from each byte for encryption, bit data is extracted from the existing data in the Modbus RTU message for encryption. The bit data is extracted in a manner of sequentially extracting from the middle bit of each byte to both sides until the length of the extracted bit data reaches the data bit length corresponding to the AES encryption algorithm for encryption; this reduces the computational amount of the AES encryption algorithm, improves the encryption efficiency, and has strong encryption security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Modbus RTU messages, and particularly to an encryption method and device for Modbus RTU messages. Background Art

[0002] With the rapid development of the power Internet of Things, the information security of power messages gradually becomes an important research direction during the information flow process. As the cornerstone of information security, the algorithms of cryptographic security have been widely studied in the academic community. However, due to the extremely strict real-time requirements of power messages, how to achieve the efficiency and security of power messages is a difficult point in the secure application of power messages.

[0003] As a widely used message in the power industry, the current Modbus RTU messages mostly only have CRC verification codes as security defense means, but the CRC verification codes of Modbus RTU messages have no ability to resist third-party malicious attacks. Since current intelligent electronic devices mostly adopt embedded hardware structures with relatively limited performance, and general encryption and decryption methods are time-consuming, there are few efficient encryption and decryption methods for Modbus RTU messages currently. Summary of the Invention

[0004] The present invention provides an encryption method, device, computer device and storage medium for Modbus RTU messages, aiming to improve the encryption strength of Modbus RTU messages while ensuring the encryption efficiency.

[0005] In a first aspect, the present invention proposes an encryption method for Modbus RTU messages, including:

[0006] Obtaining the byte length of the Modbus RTU message;

[0007] Extracting bit data from the middle position of each byte of the Modbus RTU message to obtain the bit data of the byte length quantity. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, extracting bit data from the position closest to the middle position of each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm;

[0008] Performing AES encryption on the extracted bit data to obtain the encrypted bit data;

[0009] Replacing the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

[0010] In one embodiment, extracting bit data from the middle position of each byte of the Modbus RTU message to obtain the number of bits of the byte length. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the position next to the middle position closest to each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm, including:

[0011] Extract bit data from the fourth bit of each byte of the Modbus RTU message to obtain the number of bits of the byte length;

[0012] If the length of the bit data extracted from the fourth bit is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the fifth bit of each byte;

[0013] If the length of the extracted bit data is still less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the third, sixth, second, seventh, first, and eighth bits in sequence until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm.

[0014] In one embodiment, after obtaining the byte length of the Modbus RTU message, it further includes:

[0015] Judge the size relationship between the byte length of the Modbus RTU message, the byte length encrypted by the AES encryption algorithm, and the data bit length;

[0016] If the byte length of the Modbus RTU message is less than the byte length encrypted by the AES encryption algorithm, no encryption process is performed on the Modbus RTU message;

[0017] If the byte length of the Modbus RTU message is equal to the byte length encrypted by the AES encryption algorithm, encrypt all data bits of the Modbus RTU message according to the AES encryption algorithm;

[0018] If the byte length of the Modbus RTU message is greater than the byte length encrypted by the AES encryption algorithm and less than the data bit length encrypted by the AES encryption algorithm, execute the step "Extract bit data from the middle position of each byte to obtain the number of bits of the byte length. If the length of the bit data is less than the data length encrypted by the AES encryption algorithm, extract bit data from the position next to the middle position closest to each byte until the length of the extracted bit data reaches the data length encrypted by the AES encryption algorithm";

[0019] If the byte length of the Modbus RTU message is greater than the data bit length encrypted by the AES encryption algorithm, extract bit data of the corresponding length from the Modbus RTU message according to the data bit lengths encrypted by multiple AES encryption algorithms for encryption.

[0020] In one embodiment, the data bit length encrypted by the AES encryption algorithm is 128 data bits.

[0021] In one embodiment, before obtaining the byte length of the Modbus RTU message, it further includes:

[0022] Obtain a Modbus RTU message;

[0023] Remove one byte of the address field, one byte of the function code, two bytes of the check code, and two bytes of the length data of the Modbus RTU message to obtain the body of the Modbus RTU message;

[0024] The specific way to obtain the byte length of the Modbus RTU message is to obtain the byte length of the body of the Modbus RTU message.

[0025] In one embodiment, it further includes:

[0026] Obtain several Modbus RTU messages in sequence according to the time order;

[0027] Perform encryption processing on each Modbus RTU message.

[0028] In one embodiment, after replacing the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message, it further includes:

[0029] Send the encrypted Modbus RTU message through the power Internet of Things.

[0030] In a second aspect, the present invention provides an encryption device for Modbus RTU messages, including:

[0031] A byte length acquisition unit for acquiring the byte length of a Modbus RTU message;

[0032] A bit data extraction unit, configured to extract bit data from the middle position of each byte of the Modbus RTU message to obtain the number of bit data equal to the byte length. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the position adjacent to the middle position of each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm;

[0033] An encryption unit, configured to perform AES encryption on the extracted bit data to obtain encrypted bit data;

[0034] A replacement unit, configured to replace the original bit data with the encrypted bit data to obtain an encrypted Modbus RTU message.

[0035] In a third aspect, the present invention provides a computer device, which includes a processor and a memory. A computer program is stored in the memory. When the computer program is loaded and executed by the processor, the method described in any one of the above is implemented.

[0036] In a fourth aspect, the present invention provides a computer storage medium, in which a computer program is stored. When the computer program is executed, the method described in any one of the above is implemented.

[0037] A method, device, computer device, and storage medium for encrypting a Modbus RTU message according to the present invention use the current Advanced Encryption Standard (AES) encryption algorithm to encrypt the Modbus RTU message. Since the AES encryption algorithm needs to encrypt a specific data bit length during encryption, instead of expanding the Modbus RTU message to have the same number of bytes as the data bit length required by the AES encryption algorithm during encryption and then extracting bit data from each byte for encryption, bit data is extracted from the existing data of the Modbus RTU message for encryption. Bit data is extracted in a manner of sequentially extracting from the middle bit of each byte to both sides until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm; this reduces the computational amount of the AES encryption algorithm, improves the encryption efficiency, and has strong encryption security. Description of the Drawings

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments. The drawings described below are only the corresponding drawings of some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0039] Figure 1In one embodiment of the present invention, it is a flowchart of a method for encrypting Modbus RTU messages;

[0040] Figure 2 In one embodiment of the present invention, it is a schematic diagram of the data structure of Modbus RTU messages;

[0041] Figure 3 In another embodiment of the present invention, it is a flowchart of a method for encrypting Modbus RTU messages;

[0042] Figure 4 In one embodiment of the present invention, it is a schematic diagram of the data structure of Modbus RTU messages before and after encryption. Detailed implementation manners

[0043] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of the present invention.

[0044] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present invention belongs.

[0045] Refer to Figure 1 , a method for encrypting Modbus RTU messages according to the present invention, in one embodiment, includes:

[0046] Step S01, obtaining the byte length of the Modbus RTU message.

[0047] Refer to Figure 2 , the Modbus RTU message is a widely used message in the power industry. Among them, Modbus is a serial communication protocol, and RTU is Remote Terminal Unit, the remote terminal unit. Its data structure is as shown in the figure. The Modbus RTU message includes a 1-byte address field, a 1-byte function code, an L + 2-byte data field, and 2 bytes of check code, that is, the CRC code. Among them, the data field includes two bytes of length data and L bytes of text. The method of this application embodiment mainly encrypts the L bytes of text. Generally, the length of the Modbus RTU message does not exceed 256 bytes. Therefore, the length of the text L will not be more than 250 bytes.

[0048] Step S02: Extract bit data from the middle position of each byte of the Modbus RTU message to obtain the bit data of the byte length. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the position adjacent to the middle position of each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm.

[0049] AES (Advanced Encryption Standard) was announced by the National Institute of Standards and Technology of the United States and has relatively good encryption effects. If the AES encryption algorithm cannot meet the number of bytes required for AES encryption, the original encrypted data needs to be expanded until the AES encryption requirements are met before the encryption operation can be performed.

[0050] Generally, the data bit length encrypted by the AES encryption algorithm is 128 data bits, which is 16 bytes. The data bit length encrypted by the AES encryption algorithm can also be other lengths, and this embodiment does not limit this.

[0051] Step S03: Perform AES encryption on the extracted bit data to obtain the encrypted bit data.

[0052] Step S04: Replace the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

[0053] The encryption method of the Modbus RTU message in this embodiment uses the current Advanced Encryption Standard AES encryption algorithm to encrypt the Modbus RTU message. Since the AES encryption algorithm needs to encrypt specific data bit lengths during encryption, this method does not expand the Modbus RTU message to have the same number of bytes as the data bit length required during AES encryption and then extract bit data from each byte for encryption. Instead, it extracts bit data from the existing data in the Modbus RTU message and extracts bit data in the way of sequentially extracting from the middle bit of each byte to both sides until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm. This method reduces the computational amount of the AES encryption algorithm, improves the encryption efficiency, fully selects the bit data in the Modbus RTU message for encryption, and has strong encryption security.

[0054] In one of the embodiments, refer to Figure 3 , the encryption method of the Modbus RTU message includes:

[0055] Step S201: Obtain the byte length of the Modbus RTU message.

[0056] Step S202, determine the size relationship among the byte length L of the Modbus RTU message, the byte length L1 corresponding to the AES encryption algorithm, and the data bit length L2.

[0057] Taking the data bit length corresponding to the AES encryption algorithm as 128-bit data bits and 16 bytes as an example, that is, L1 = 16 and L2 = 128.

[0058] Step S203, if L < L1, do not perform encryption processing on the Modbus RTU message.

[0059] When the byte length of the Modbus RTU message is less than 16 bytes, since the content of the message body is too small, in order to follow the Modbus RTU message format and avoid destroying the original message format due to the need to extend to 16 bytes after using the AES encryption algorithm, the content of the message body is not encrypted, and the content of the Modbus RTU message is directly sent through the power Internet of Things.

[0060] Step S204, if L = L1, encrypt all data bits of the Modbus RTU message according to the AES encryption algorithm.

[0061] When the byte length of the Modbus RTU message is equal to 16 bytes, it exactly meets the requirements of the AES encryption algorithm. In order to ensure the security of the message during transmission, all the content of the message body, that is, all data bits, is encrypted, and all the content of the message body is encrypted through the AES algorithm.

[0062] Step S205, if L1 < L <= L2, extract bit data from the middle position of each byte to obtain the bit data with the number of the byte length. If the length of the bit data is less than the data length corresponding to the AES encryption algorithm, extract bit data from the position next to the middle position closest to the middle position of each byte until the length of the extracted bit data reaches the data length corresponding to the AES encryption algorithm.

[0063] When the byte length of the Modbus RTU message is greater than 16 bytes and less than 128 bytes, extract bit data from the middle position of each byte to obtain the bit data with the number of the byte length. Specifically, in one embodiment, extract bit data from the fourth bit of each byte of the Modbus RTU message to obtain the bit data with the number of the byte length;

[0064] If the length of the bit data extracted from the fourth bit is less than the data bit length corresponding to the AES encryption algorithm, extract bit data from the fifth bit of each byte;

[0065] If the length of the extracted bit data is still less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the third bit, the sixth bit, the second bit, the seventh bit, the first bit, and the eighth bit in sequence until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm.

[0066] In one embodiment, refer to Figure 4 , if the byte length of the Modbus RTU message is 124 bytes, extract the fourth bit of each byte to obtain 124 bit data. 4 more bit data are needed to obtain 128 bit data, which meets the requirement of the data bit length encrypted by the AES encryption algorithm. Then extract 4 bit data from the fifth bit of four bytes of the Modbus RTU message to obtain 128 bit data in total.

[0067] Step S206, if L > L2, extract bit data of the corresponding length from the Modbus RTU message according to the data bit lengths encrypted by multiple AES encryption algorithms for encryption.

[0068] When the byte length of the Modbus RTU message is greater than 128 bytes, since the bit data length obtained after extracting one bit data from each byte is greater than 128, exceeding the data bit length required for AES encryption, it can be encrypted according to the fact that two AES encryption algorithms require 32 bytes and 256 data bits.

[0069] Step S207, perform AES encryption on the extracted bit data to obtain the encrypted bit data.

[0070] Step S208, replace the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

[0071] Refer to Figure 4 , if the byte length of the Modbus RTU message is 124 bytes, after encrypting the Modbus RTU message through the AES encryption algorithm, replace the original data bits of the Modbus RTU message with the encrypted result to obtain the encrypted Modbus RTU message. Then send the encrypted Modbus RTU message through the power Internet of Things.

[0072] In specific implementation, obtain a number of Modbus RTU messages in chronological order, perform the above encryption processing on each Modbus RTU message, and then send them out through the power Internet of Things in sequence.

[0073] The encryption method of the Modbus RTU message in this embodiment encrypts the Modbus RTU message in chronological order. During the encryption process, an appropriate encryption method is selected according to the data length of the Modbus RTU message. The AES encryption algorithm is mainly used. The data bit length required by the AES encryption algorithm is extracted from the existing data of the Modbus RTU message. Specifically, it is selected in the way of expanding from the middle of each byte to both sides. No content is added to the text during the encryption process, reducing the memory occupation during message encryption. Only the existing content itself is encrypted, reducing the computational amount in the encryption process and improving the encryption efficiency. And starting from the content in the middlemost position of each byte for encryption can maximally block the coherence of the encrypted message and ensure the security of the message.

[0074] The present invention also proposes an encryption device for Modbus RTU messages. In one embodiment, it includes:

[0075] A byte length acquisition unit for acquiring the byte length of the Modbus RTU message;

[0076] A bit data extraction unit for extracting bit data from the middle position of each byte of the Modbus RTU message to obtain the bit data with the number of byte lengths. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, bit data is extracted from the position closest to the middle position of each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm;

[0077] An encryption unit for performing AES encryption on the extracted bit data to obtain the encrypted bit data;

[0078] A replacement unit for replacing the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

[0079] In one embodiment, the bit data extraction unit is specifically used for:

[0080] Extracting bit data from the fourth bit of each byte of the Modbus RTU message to obtain the bit data with the number of byte lengths;

[0081] If the length of the bit data extracted from the fourth bit is less than the data bit length encrypted by the AES encryption algorithm, bit data is extracted from the fifth bit of each byte;

[0082] If the length of the extracted bit data is still less than the data bit length encrypted by the AES encryption algorithm, bit data is extracted successively from the third bit, the sixth bit, the second bit, the seventh bit, the first bit, and the eighth bit until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm.

[0083] In one embodiment, the encryption device for Modbus RTU messages further includes:

[0084] A judgment unit, configured to judge the magnitude relationship between the byte length of the Modbus RTU message, the byte length encrypted by the AES encryption algorithm, and the data bit length;

[0085] If the byte length of the Modbus RTU message is less than the byte length encrypted by the AES encryption algorithm, no encryption process is performed on the Modbus RTU message;

[0086] If the byte length of the Modbus RTU message is equal to the byte length encrypted by the AES encryption algorithm, all data bits of the Modbus RTU message are encrypted according to the AES encryption algorithm;

[0087] If the byte length of the Modbus RTU message is greater than the byte length encrypted by the AES encryption algorithm and less than the data bit length encrypted by the AES encryption algorithm, perform the step of "extracting bit data from the middle position of each byte to obtain the bit data of the byte length quantity. If the length of the bit data is less than the data length encrypted by the AES encryption algorithm, extract bit data from the position next to the middle position closest to the middle position in each byte until the length of the extracted bit data reaches the data length encrypted by the AES encryption algorithm";

[0088] If the byte length of the Modbus RTU message is greater than the data bit length encrypted by the AES encryption algorithm, extract bit data of the corresponding length from the Modbus RTU message according to the data bit length encrypted by multiple AES encryption algorithms for encryption.

[0089] In one embodiment, the encryption device for Modbus RTU messages further includes:

[0090] A data processing unit, configured to obtain a Modbus RTU message; remove one byte of address field, one byte of function code, two bytes of check code, and two bytes of length data from the Modbus RTU message to obtain the body of the Modbus RTU message;

[0091] The specific method for obtaining the byte length of the Modbus RTU message is to obtain the byte length of the body of the Modbus RTU message.

[0092] In one embodiment, the encryption device for Modbus RTU messages further includes:

[0093] A message acquisition unit, configured to sequentially acquire a plurality of Modbus RTU messages in chronological order; and perform encryption processing on each of the Modbus RTU messages.

[0094] In one embodiment, the encryption device for Modbus RTU messages further includes:

[0095] A sending unit, configured to send the encrypted Modbus RTU message through the power Internet of Things.

[0096] An embodiment of the present invention further provides a computer device, which includes a processor and a memory, and a computer program is stored in the memory. When the computer program is loaded and executed by the processor, the method steps described in any one of the above method embodiments are implemented.

[0097] An embodiment of the present invention further provides a computer storage medium, in which a computer program is stored. When the computer program is executed, the method steps described in any one of the above method embodiments are implemented.

[0098] In the above embodiments provided by the present invention, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, and the indirect coupling or communication connection of the device or unit may be in an electrical, mechanical or other form.

[0099] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0100] In addition, each functional unit in various embodiments of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium.

[0101] Based on such an understanding, the technical solution of the present application, in essence, or the part that makes a contribution, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a mobile terminal, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.

[0102] In summary, although the present invention has been disclosed above with preferred embodiments, the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the concept of the technical solution of the present invention, makes equivalent substitutions or changes, and should be covered within the protection scope of the present invention.

[0103] The technical features of the above-described embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.

Claims

1. A method for encrypting Modbus RTU messages, characterized in that, Including: Obtain the byte length of the Modbus RTU message; Extract bit data from the middle position of each byte of the Modbus RTU message to obtain the bit data of the byte length quantity. If the length of the bit data is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the position next to the middle position closest to each byte until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm. In this step, it specifically includes, Extract bit data from the fourth bit of each byte of the Modbus RTU message to obtain the bit data of the byte length quantity; If the length of the bit data extracted from the fourth bit is less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the fifth bit of each byte; If the length of the extracted bit data is still less than the data bit length encrypted by the AES encryption algorithm, extract bit data from the third bit, sixth bit, second bit, seventh bit, first bit, and eighth bit in sequence until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm; Perform AES encryption on the extracted bit data to obtain the encrypted bit data; Replace the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

2. The method according to claim 1, wherein After obtaining the byte length of the Modbus RTU message, it further includes: Judge the magnitude relationship between the byte length of the Modbus RTU message, the byte length encrypted by the AES encryption algorithm, and the data bit length; If the byte length of the Modbus RTU message is less than the byte length encrypted by the AES encryption algorithm, do not perform encryption processing on the Modbus RTU message; If the byte length of the Modbus RTU message is equal to the byte length encrypted by the AES encryption algorithm, encrypt all data bits of the Modbus RTU message according to the AES encryption algorithm; If the byte length of the Modbus RTU message is greater than the byte length encrypted by the AES encryption algorithm and less than the data bit length encrypted by the AES encryption algorithm, execute the step "Extract bit data from the middle position of each byte to obtain the bit data of the byte length quantity. If the length of the bit data is less than the data length encrypted by the AES encryption algorithm, extract bit data from the position next to the middle position closest to each byte until the length of the extracted bit data reaches the data length encrypted by the AES encryption algorithm"; If the byte length of the Modbus RTU message is greater than the data bit length encrypted by the AES encryption algorithm, extract bit data of the corresponding length from the Modbus RTU message according to the data bit length encrypted by multiple AES encryption algorithms for encryption.

3. The method according to claim 1, wherein The data bit length encrypted by the AES encryption algorithm is 128 data bits.

4. The method according to claim 1, wherein Before obtaining the byte length of the Modbus RTU message, it further includes: Obtain the Modbus RTU message; Remove one byte of address field, one byte of function code, two bytes of check code and two bytes of length data from the Modbus RTU message to obtain the body of the Modbus RTU message; The specific method for obtaining the byte length of the Modbus RTU message is to obtain the byte length of the body of the Modbus RTU message.

5. The method according to claim 1, wherein It further includes: Obtain a number of Modbus RTU messages in chronological order; Perform encryption processing on each of the Modbus RTU messages.

6. The method according to claim 1, wherein After replacing the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message, it further includes: Send the encrypted Modbus RTU message through the power Internet of Things.

7. An encryption device for Modbus RTU messages, characterized in that, It includes: A byte length acquisition unit for acquiring the byte length of the Modbus RTU message; A bit data extraction unit for extracting bit data from the fourth bit of each byte of the Modbus RTU message to obtain the bit data of the byte length quantity; if the length of the bit data extracted from the fourth bit is insufficient for the data bit length encrypted by the AES encryption algorithm, extract bit data from the fifth bit of each byte; if the length of the extracted bit data is still insufficient for the data bit length encrypted by the AES encryption algorithm, extract bit data from the third bit, sixth bit, second bit, seventh bit, first bit, and eighth bit in sequence until the length of the extracted bit data reaches the data bit length encrypted by the AES encryption algorithm; A judgment unit for judging the size of the byte length of the Modbus RTU message, the byte length encrypted by the AES encryption algorithm, and the data bit length; A data processing unit for obtaining the Modbus RTU message; removing one byte of address field, one byte of function code, two bytes of check code and two bytes of length data from the Modbus RTU message to obtain the body of the Modbus RTU message; An encryption unit for performing AES encryption on the extracted bit data to obtain encrypted bit data; A replacement unit for replacing the original bit data with the encrypted bit data to obtain the encrypted Modbus RTU message.

8. A computer device, characterized in that, The computer device includes a processor and a memory, and a computer program is stored in the memory. When the computer program is loaded and executed by the processor, the method according to any one of claims 1 to 7 is implemented.

9. A computer storage medium, characterized in that, A computer program is stored in the computer storage medium. When the computer program is executed, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Automobile CAN bus encryption method

    CN110545257A

  • LoRa security encryption communication module

    CN114501433A