Data encryption method, decryption method and device

By generating target key data and encrypting CAN bus data using SM4 or AES encryption algorithms, combined with a synchronization message mechanism, the data security problem caused by plaintext transmission on the CAN bus is solved, achieving an efficient data encryption and decryption process and improving the security and transmission speed of the vehicle network.

CN115396190BActive Publication Date: 2024-11-22BEIJING TOPSEC NETWORK SECURITY TECH +2
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202211020876.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-24
Publication Date
2024-11-22
Estimated Expiration
2042-08-24

AI Technical Summary

Technical Problem

In vehicle networks, the CAN bus communication protocol transmits data in plaintext, which leads to data security issues and poses a threat of user information leakage and modification.

Method used

The target key data is generated by referring to the length of the data to be encrypted. The data is then encrypted using SM4 or AES encryption algorithms. A synchronization message mechanism is introduced to generate a temporary session key to avoid replay attacks. Logical operations are performed bit by bit to improve security and data transmission speed.

Benefits of technology

It effectively prevents data theft, improves data transmission security and speed, avoids the complexity of multi-frame transmission, and enhances the security of CAN bus communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115396190B_ABST
    Figure CN115396190B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a method for data encryption, a method for decryption, and a device, the method comprising: obtaining initial key data; intercepting and processing the initial key data according to the length of a frame of message to be encrypted to obtain target key data; encrypting the message to be encrypted by the target key data to obtain encrypted data; and sending the encrypted data. Some embodiments of the present application determine the length of encrypted data by the length of a frame of message data to be encrypted, so that each frame of data can be encrypted and sent independently, thereby improving the speed of data processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data encryption. Specifically, embodiments of the present application relate to a data encryption method, a decryption method and a device. Background Art

[0002] In vehicle networks, CAN bus is a commonly used communication protocol, and most of its data is transmitted in plain text. Although this method has the advantages of low cost and high performance, the problem of data security is particularly prominent in the era of rapid development of the Internet of Vehicles, which will lead to the threat of user information leakage and CAN bus information modification. Summary of the invention

[0003] The purpose of the embodiments of the present application is to provide a data encryption method, a decryption method and a device. Through the embodiments of the present application, the encrypted data can be obtained by referring to the length of the data to be encrypted, thereby avoiding the problem of having to transmit multiple frames and reducing the complexity of data processing.

[0004] In a first aspect, an embodiment of the present application provides a method for data encryption, the method comprising: obtaining initial key data; intercepting the initial key data according to the length of a frame of a message to be encrypted to obtain target key data; encrypting the message to be encrypted using the target key data to obtain encrypted data; and sending the encrypted data.

[0005] Some embodiments of the present application determine the length of encrypted data by the length of a frame of message data to be encrypted, so that each frame of data can be encrypted and sent independently, thereby improving the speed of data processing.

[0006] In some embodiments, the obtaining of initial key data includes: using an encryption algorithm to generate a temporary session key to obtain the initial key data; intercepting the initial key data according to the length of a frame of message to be encrypted to obtain target key data includes: intercepting data with the same number of bits as the length of the frame of message to be encrypted from the temporary session key to obtain the target key data.

[0007] Some embodiments of the present application obtain a temporary session key through a symmetric encryption algorithm and trim the temporary session key to obtain target key data, which can effectively avoid replay attacks.

[0008] In some embodiments, the encryption algorithm is SM4 or AES encryption algorithm, and the frame of message to be encrypted is a message transmitted on the CAN bus, wherein the use of a symmetric encryption algorithm to generate a temporary session key includes: assembling first data and second data to obtain 16 bytes of combined data, wherein the first data is a synchronization message transmitted on the CAN bus; encrypting the combined data using the SM4 key to obtain the temporary session key.

[0009] Some embodiments of the present application generate temporary session keys by introducing synchronization messages transmitted on the CAN bus, thereby improving the security of the entire solution.

[0010] In some embodiments, the assembling of the first data and the second data to obtain 16-byte combined data includes: receiving the synchronization message transmitted via the CAN bus to obtain the first data; obtaining user-defined padding data as the second data; and assembling the synchronization message and the user-defined padding data into the combined data.

[0011] In order to encrypt messages on the CAN bus using the SM4 algorithm, some embodiments of the present application need to generate a synchronization message and obtain data that can be encrypted using the SM4 algorithm based on the synchronization message and padding data.

[0012] In some embodiments, the CAN bus uses a fixed-length transmission cycle to send each synchronization message, and updates the sent synchronization message after each transmission.

[0013] Some embodiments of the present application send synchronization messages for generating encrypted data via the CAN bus, and the synchronization messages are updateable, so a temporary session key can be obtained to prevent the system from being attacked by replay.

[0014] In some embodiments, the synchronization message is generated by a gateway device connected to the CAN bus, and the gateway device is configured to perform the following operations: setting the initial value of the synchronization message to 0 after each power-on; after each synchronization message is sent, the value of the synchronization message is incremented to generate a synchronization message to be sent next time; and when it is confirmed that the value of the synchronization message reaches a set threshold, a clearing operation is performed.

[0015] Some embodiments of the present application periodically update synchronization messages through a self-increment operation, thereby implementing an update of a temporary session key and avoiding replay attacks on the system.

[0016] In some embodiments, encrypting the message to be encrypted by using the target key data to obtain encrypted data includes: performing logical operations on corresponding bits of the target key data and the message to be encrypted to obtain the encrypted data.

[0017] Some embodiments of the present application encrypt the data to be encrypted by performing logical operations bit by bit, so that the encrypted data can still be transmitted on the original bus, thereby improving the security of the data to be sent and increasing the data transmission speed as much as possible.

[0018] In some embodiments, the logical operation is an exclusive-OR operation.

[0019] In a second aspect, some embodiments of the present application provide a method for data decryption, the method comprising: receiving encrypted data obtained using the encryption method as described in any embodiment of the first aspect; generating target key data, wherein the target key data is obtained by intercepting initial key data according to the length of a frame of a message to be encrypted; and decrypting the encrypted data according to the target key data to obtain the data to be encrypted.

[0020] In some embodiments, the generating the target key data includes: generating a temporary session key according to a synchronization message received from a CAN bus, wherein the temporary session key is the target key data.

[0021] In some embodiments, the numerical value carried by the synchronization message each time is self-increasing, wherein the generation of a temporary session key based on the synchronization message received from the CAN bus includes: if it is verified that the generation of the temporary session key based on the first numerical value carried by the synchronization message cannot complete the decryption operation of the encrypted data, then obtaining at least one numerical value close to the first numerical value, and decrypting the encrypted data based on the at least one numerical value, wherein the at least one numerical value includes a number obtained by adding one or subtracting one from the first numerical value.

[0022] In a third aspect, some embodiments of the present application provide a data encryption device, comprising: an initial key data acquisition module, configured to acquire initial key data; a target key generation module, configured to intercept and process the initial key data according to the length of a frame of a message to be encrypted to obtain target key data; an encryption module, configured to encrypt the message to be encrypted using the target key data to obtain encrypted data; and a sending module, configured to send the encrypted data.

[0023] In a fourth aspect, some embodiments of the present application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the method described in any embodiment of the first aspect.

[0024] In a fifth aspect, some embodiments of the present application provide an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, can implement a method as described in any embodiment of the first aspect.

[0025] In the sixth aspect, some embodiments of the present application provide a data decryption device, the device comprising: a receiving module, configured to receive encrypted data obtained using the encryption method as described in any embodiment of the first aspect; a target key generation module, configured to generate target key data, wherein the target key data is obtained by intercepting initial key data according to the length of a frame of a message to be encrypted; and a decryption module, configured to decrypt the encrypted data according to the target key data to obtain the data to be encrypted. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 One of the CAN bus architecture diagrams provided in the embodiment of the present application;

[0028] Figure 2 The second CAN bus architecture diagram provided for the embodiment of the present application;

[0029] Figure 3 One of the flow charts of the data encryption method provided in the embodiment of the present application;

[0030] Figure 4 A schematic diagram of the data encryption process provided by an embodiment of the present application;

[0031] Figure 5 The second flowchart of the data encryption method provided in the embodiment of the present application;

[0032] Figure 6 A schematic diagram of the data decryption process provided by an embodiment of the present application;

[0033] Figure 7 A flowchart of a data decryption method provided in an embodiment of the present application;

[0034] Figure 8 A block diagram of the data encryption device provided in an embodiment of the present application;

[0035] Fig. 9A block diagram of the composition of a data decryption device provided in an embodiment of the present application;

[0036] Fig.10 A schematic diagram of the composition of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0037] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0038] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0039] Please see Figure 1 , Figure 1 CAN bus architecture diagram, including a CAN bus 120 and multiple nodes mounted on the bus 120, for example, Figure 1 The first ECU node 101, the second ECU node 102, the third ECU node 103, the fourth ECU node 104, the fifth ECU node 105 and the sixth ECU node 106 are shown. For example, these nodes are subsystems that need to transmit data via the CAN bus. If the CAN bus is a bus on a car, the nodes exemplarily include an anti-theft subsystem or an air conditioning entertainment subsystem on the car. The embodiments of the present application do not limit the type of specific subsystems of the nodes.

[0040] Some embodiments of the present application can be used to Figure 1 The messages to be sent generated by each node are encrypted to improve the security of the entire system.

[0041] like Figure 2 As shown in the encryption system architecture diagram of some embodiments of the present application, it can be seen that Figure 1 The difference is that some embodiments of the present application are equipped with encryption modules corresponding to each node, for example, a first encryption module 111 is arranged corresponding to the first ECU node 101, a second encryption module 112 is arranged corresponding to the second ECU node 102, a third encryption module 113 is arranged corresponding to the third ECU node 103, a fourth encryption module 114 is arranged corresponding to the fourth ECU node 104, a fifth encryption module 115 is arranged corresponding to the fifth ECU node 105, and a sixth encryption module 116 is arranged corresponding to the sixth ECU node 106.

[0042] It should be noted that Figure 2 Each encryption module may also be integrated on the corresponding node.

[0043] The following is an example of Figure 2 The encryption method implemented by each encryption module.

[0044] like Figure 3 As shown, an embodiment of the present application provides a method for data encryption, the method comprising:

[0045] S101, obtaining initial key data.

[0046] S102, intercepting and processing the initial key data according to the length of a frame of the message to be encrypted to obtain target key data.

[0047] For example, in some embodiments of the present application, S101 exemplarily includes: using an encryption algorithm to generate a temporary session key to obtain the initial key data. The corresponding S102 exemplarily includes: intercepting data with the same number of bits as the length of the one frame of the message to be encrypted from the temporary session key to obtain the target key data. Some embodiments of the present application obtain a temporary session key by using a symmetric encryption algorithm and trimming the temporary session key to obtain the target key data, which can effectively avoid replay attacks.

[0048] In some embodiments, the encryption algorithm is SM4 or AES encryption algorithm, the one frame of message to be encrypted is a message transmitted on the CAN bus, wherein the use of a symmetric encryption algorithm to generate a temporary session key includes: assembling first data and second data to obtain 16 bytes of combined data, wherein the first data is a synchronization message transmitted on the CAN bus; encrypting the combined data using the SM4 key key to obtain the temporary session key. Some embodiments of the present application generate a temporary session key by introducing a synchronization message transmitted on the CAN bus, thereby improving the security of the entire solution.

[0049] In some embodiments, the assembling of the first data and the second data to obtain 16-byte combined data includes: receiving the synchronization message transmitted via the CAN bus to obtain the first data; obtaining user-defined padding data as the second data; and assembling the synchronization message and the user-defined padding data into the combined data.

[0050] In order to encrypt messages on the CAN bus using the SM4 algorithm, some embodiments of the present application need to generate a synchronization message and obtain data that can be encrypted using the SM4 algorithm based on the synchronization message and padding data.

[0051] In some embodiments, the CAN bus uses a fixed-length transmission cycle to send each synchronization message, and updates the sent synchronization message after each transmission.

[0052] Some embodiments of the present application send synchronization messages for generating encrypted data via the CAN bus, and the synchronization messages are updateable, so a temporary session key can be obtained to prevent the system from being attacked by replay.

[0053] In some embodiments, the synchronization message is generated by a gateway device connected to the CAN bus, and the gateway device is configured to perform the following operations: setting the initial value of the synchronization message to 0 after each power-on; after each synchronization message is sent, the value of the synchronization message is incremented to generate a synchronization message to be sent next time; and when it is confirmed that the value of the synchronization message reaches a set threshold, a clearing operation is performed.

[0054] Some embodiments of the present application periodically update synchronization messages through a self-increment operation, thereby implementing an update of a temporary session key and avoiding replay attacks on the system.

[0055] S103, encrypting the message to be encrypted by using the target key data to obtain encrypted data.

[0056] For example, in some embodiments of the present application, S103 exemplarily includes: performing an AND logic operation on the corresponding bits of the target key data and the message to be encrypted, respectively, to obtain the encrypted data. Some embodiments of the present application perform an encryption operation on the data to be encrypted by performing a logic operation bit by bit, so that the encrypted data can still be transmitted on the original bus, and the data transmission speed can be increased as much as possible while improving the security of the data to be sent. For example, the logic operation is an XOR operation.

[0057] S104: Send the encrypted data.

[0058] It should be noted that Figure 2 It is also necessary to add a decryption module (not shown in the figure) to each node to perform operations opposite to the encryption operations of the encryption module.

[0059] Some embodiments of the present application provide a method for data decryption, the method comprising: receiving a data decryption method as described above Figure 3 The invention comprises the following steps: obtaining encrypted data by the encryption method described in any one of the embodiments; generating target key data, wherein the target key data is obtained by intercepting initial key data according to the length of a frame of message to be encrypted; and decrypting the encrypted data according to the target key data to obtain the data to be encrypted.

[0060] For example, in some embodiments, the generating the target key data includes: generating a temporary session key according to a synchronization message received from a CAN bus, wherein the temporary session key is the target key data.

[0061] For example, in some embodiments, the numerical value carried by the synchronization message each time is self-increasing, wherein the generation of a temporary session key based on the synchronization message received from the CAN bus includes: if it is verified that the generation of the temporary session key based on the first numerical value carried by the synchronization message cannot complete the decryption operation of the encrypted data, then obtaining at least one numerical value close to the first numerical value, and decrypting the encrypted data based on the at least one numerical value, wherein the at least one numerical value includes a number obtained by adding one or subtracting one from the first numerical value.

[0062] Some embodiments of the present application determine the length of encrypted data by the length of a frame of message data to be encrypted, so that each frame of data can be encrypted and sent independently, thereby improving the speed of data processing.

[0063] The encryption and decryption methods provided by some embodiments of the present application are exemplarily described below in conjunction with the SM4 encryption algorithm.

[0064] It should be noted that in some embodiments of the present application, the length of the message transmitted by the CAN bus is 64bit, but the SM4 block encryption algorithm requires 128bit data. If the CAN message is directly encrypted, it is also necessary to fill in data or merge two groups of data before encryption, which results in the need to perform a CAN bus multi-frame transmission mode for sending each group of data. Some embodiments of the present application adopt a method of generating a 64bit session key (i.e., the target key data of the embodiment of the present application is the same as the length of a frame of CAN message to be encrypted). However, since the encrypted data obtained by the SM4 algorithm is longer than a frame of message to be encrypted, how to cleverly improve the SM4 algorithm (for example, using a synchronization message to generate a temporary session key, and then intercepting the temporary session key) to implement the encryption method of the present application has become a technical problem to be solved. Using some embodiments of the present application can effectively avoid the problem of data transmission difficulties caused by the encryption of multiple frames of data to be encrypted as a whole in related technologies. In addition, a synchronization message is also introduced in some embodiments of the present application for calculating the session key. The session key obtained by the synchronization message is used to encrypt CAN data, and since the session key is also updated regularly, the security of the data is increased.

[0065] In some embodiments of the present application, the SM4 encryption algorithm and the synchronization message mechanism are introduced on the CAN bus to generate a session key and encrypt the CAN message with the session key. The data of the sending node is encrypted before being sent, and the receiving node receives the ciphertext data and decrypts it before executing it, so that the data transmitted on the bus is ciphertext data, thereby achieving the purpose of preventing data theft.

[0066] like Figure 4As shown, some embodiments of the present application provide a data encryption method, the encryption module exemplarily includes an SM4 encryption processing module, which receives data from each ECU node (named Figure 4 The ECU sending node) generates a frame of plaintext data to be sent (i.e., a frame of encrypted message), and the SM4 encryption processing module encrypts the plaintext data to obtain encrypted data (i.e., Figure 4 The encrypted data is sent to other nodes via the CAN BUS.

[0067] The SM4 algorithm is a block cipher algorithm, which consists of an encryption and decryption algorithm and a key expansion algorithm. Both the encryption and decryption algorithm and the key expansion algorithm use a 32-round nonlinear iterative structure, in which the algorithm structure of the encryption and decryption algorithms is the same, and the order of key use is reversed. The basic condition for ensuring the security of a symmetric encryption algorithm is that it has a sufficient key length. The SM4 algorithm has the same key length and packet length of 128 bits as the AES algorithm, so it is more secure than the 3DES algorithm. Some embodiments of the present application provide a method for encrypting CAN data securely by using a symmetric encryption algorithm based on SM4 to generate a session key and intercepting the high 64-bit session key.

[0068] Combine the following Figure 5 The working process of the SM4 encryption processing module is described as follows. Figure 5 As shown, the encryption processing method of some embodiments of the present application includes:

[0069] Step 1: Add a synchronization message type CAN data in CAN transmission. The synchronization message (for example, the synchronization message can be Figure 2 The synchronization message generation device 130 generates and sends to the CAN bus) with a sending cycle of 10s. It is initialized to 0 after each power-on and starts to send. When the value reaches the maximum value, it will be initialized to 0. The value will increase after each transmission. The synchronization message is 8 bytes. The 8-byte synchronization message and the user-defined fixed 8-byte padding data are assembled into 16 bytes of data;

[0070] Step 2: Use the assembled 16-byte SynText data and the SM4 key to perform SM4 encryption calculation to obtain a new encrypted data (as an example of the initial key data), take the high 8 bytes of the encrypted data SessionKey, and use it as the session key for encrypting the real CAN data.

[0071] Figure 5 SynText is characterized by 8 bytes of synchronization message (as an example of first data) and 8 bytes of user-defined fixed data (as an example of second data). Figure 5 The Key is the 16-byte key set by the user for SM4. Figure 5 The SessionKey is used to represent the 16-byte data obtained by SM4 encryption of SynText, and then the high 8 bytes are taken as the session key (as an example of the target key data).

[0072] Step 3: Use SessionKey and the 8-byte PlainText that CAN actually needs to send to perform an XOR operation to obtain the encrypted data CipherText.

[0073] Figure 5 The PlainText represents the actual 8-byte plaintext CAN message that needs to be sent. Figure 5 The ⊕ symbol represents the XOR operation, Figure 5 The CipherText represents the encrypted 8-byte CAN message.

[0074] like Figure 6 As shown, the decryption process of some embodiments of the present application includes: reading the encrypted message from the CAN bus, that is, Figure 6 The ciphertext data is Figure 6 The SM4 decryption processing module decrypts the ciphertext data to obtain Figure 6 The plaintext data is then sent to the ECU receiving node (the node is Figure 2 any node of ).

[0075] Combine the following Figure 7 Briefly describe the decryption process.

[0076] Step 1: Receive the synchronization message in CAN transmission. The synchronization message is 8 bytes. Assemble the 8-byte synchronization message and the user-defined fixed 8-byte padding data into 16 bytes of data;

[0077] Step 2: Use the assembled 16-byte SynText data and the SM4 key to perform SM4 encryption calculation to obtain a new encrypted data. Take the high 8-byte data SessionKey of the encrypted data and use it as the session key for encrypting the real CAN data.

[0078] Step 3: Use SessionKey and the 8-byte ciphertext CipherText that CAN actually needs to send to perform an XOR operation to obtain the decrypted real data Plaintext.

[0079] Some embodiments of the present application are based on the CAN bus network, and describe the use of an encryption method proposed by the present invention to improve the security of CAN bus data transmission. For example, the specific process is as follows:

[0080] 1. During the ECU communication process, initialization is required first to synchronize the synchronization messages.

[0081] 2. After the synchronization message is successfully synchronized, when the sending ECU sends CAN data, the original CAN message is encrypted according to the encryption method mentioned in this method and then sent on the CAN bus.

[0082] 3. When the ECU starts to receive data after initialization, it first calculates the temporary session key based on the information in the synchronization message, then obtains the encrypted data on the CAN bus, decrypts it, and then performs the corresponding action.

[0083] It is not difficult to understand that the technical advantages of some embodiments of the present application include:

[0084] 1) The national secret SM4 algorithm is adopted; the algorithm has high security.

[0085] 2) Using a synchronous message mechanism can effectively prevent replay attacks.

[0086] 3) A 64-bit session key is used to avoid the problem of having to transmit multiple frames and reduce processing complexity.

[0087] That is to say, some embodiments of the present application are applied in the scenario of CAN encrypted transmission, and the key technical points involved are as follows: the SM4 algorithm is used to generate a temporary session key, and the 8-bit session key is intercepted to encrypt the 8-bit CAN message. The mechanism of synchronous message is also adopted, and the mechanism of temporary session key is generated by using synchronous message.

[0088] For example, you can Figure 2 The synchronization message generating device 130 obtains the required synchronization message, and the device can be a gateway device connected to the CAN bus, etc.

[0089] Please refer to Figure 8 , Figure 8 The data encryption device provided in the embodiment of the present application is shown. It should be understood that the device is similar to the above-mentioned Figure 3 The method embodiment corresponds to the method embodiment, and can execute each step involved in the above method embodiment. The specific functions of the device can refer to the description above. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in the memory in the form of software or firmware or solidified in the operating system of the device. The data encryption device includes: an initial key data acquisition module 801, a target key data generation module 802, an encryption module 803 and a sending module 804.

[0090] Figure 8The initial key data acquisition module 801 is configured to acquire initial key data.

[0091] Figure 8 The target key data generation module 802 is configured to intercept and process the initial key data according to the length of a frame of the message to be encrypted to obtain the target key data.

[0092] Figure 8 The encryption module 803 is configured to encrypt the message to be encrypted using the target key data to obtain encrypted data.

[0093] Figure 8 The sending module 804 is configured to send the encrypted data.

[0094] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.

[0095] Please refer to Fig. 9 , Fig. 9 The device for data decryption provided by the embodiment of the present application is shown. It should be understood that the device corresponds to the above-mentioned decryption method embodiment and can execute the various steps involved in the above-mentioned method embodiment. The specific functions of the device can be found in the description above. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the operating system of the device. The data decryption device includes: a receiving module 810, a target key generation module 820 and a decryption module 830.

[0096] The receiving module is configured to receive encrypted data obtained by using the encryption method as described above.

[0097] The target key generation module is configured to generate target key data, wherein the target key data is obtained by intercepting and processing the initial key data according to the length of a frame of the message to be encrypted.

[0098] The decryption module is configured to decrypt the encrypted data according to the target key data to obtain the data to be encrypted.

[0099] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.

[0100] Some embodiments of the present application provide a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the method described in any embodiment of the above-mentioned decryption method and encryption method can be implemented.

[0101] like Fig.10 As shown, some embodiments of the present application provide an electronic device 900, which includes a memory 910, a processor 920, a bus 930, and a computer program stored in the memory 910 and executable on the processor 920, wherein the processor 920 can implement the method described in any embodiment of the encryption or decryption method as described above when reading the program from the memory 910 through the bus 930 and executing the program.

[0102] Processor 920 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 920 can be a microprocessor.

[0103] The memory 910 may be used to store instructions executed by the processor 920 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some or all functions of one or more modules described in the embodiments of the present application. The processor 920 of the disclosed embodiment may be used to execute instructions in the memory 910 to implement the above-mentioned encryption or decryption method. The memory 910 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.

[0104] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0105] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0106] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0107] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0108] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0109] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

Claims

1. A method for data encryption, characterized in that: The method comprises: Get initial key data; According to the length of a frame of message to be encrypted, the initial key data is intercepted and processed to obtain target key data; Encrypting the message to be encrypted by using the target key data to obtain encrypted data; sending the encrypted data; The obtaining of initial key data comprises: Generate a temporary session key using an encryption algorithm to obtain the initial key data, wherein the encryption algorithm is SM4 or AES encryption algorithm. The step of using an encryption algorithm to generate a temporary session key comprises: Assembling the first data and the second data to obtain 16-byte combined data, wherein the first data is a synchronization message transmitted on the CAN bus; and the second data is user-defined padding data; Encrypt the combined data using the key of SM4 to obtain the temporary session key; The assembling of the first data and the second data to obtain 16 bytes of combined data includes: Receiving the synchronization message transmitted through the CAN bus to obtain the first data; Acquire user-defined filling data as the second data; The synchronization message and the user-defined padding data are assembled into the combined data.

2. The method according to claim 1, characterized in that The method of intercepting the initial key data according to the length of a frame of the message to be encrypted to obtain the target key data includes: Data having the same number of bits as the length of the one frame of message to be encrypted is intercepted from the temporary session key to obtain the target key data.

3. The method according to claim 2, characterized in that The one frame of message to be encrypted is a message transmitted on the CAN bus.

4. The method according to claim 3, characterized in that The CAN bus uses a fixed-length transmission cycle to send each synchronization message, and updates the sent synchronization message after each transmission.

5. The method according to claim 4, characterized in that The synchronization message is generated by a gateway device connected to the CAN bus, and the gateway device is configured to perform the following operations: After each power-on, the initial value of the synchronization message is set to 0; After each synchronization message is sent, the value of the synchronization message is incremented to generate the synchronization message to be sent next time; When it is confirmed that the value of the synchronization message reaches the set threshold, a clearing operation is performed.

6. The method according to any one of claims 1 to 3, characterized in that: The step of encrypting the message to be encrypted by using the target key data to obtain encrypted data includes: The target key data and corresponding bits of the message to be encrypted are respectively subjected to logical operations to obtain the encrypted data.

7. The method according to claim 6, characterized in that The logic operation is an exclusive OR operation.

8. A method for data decryption, characterized in that: The method comprises: Receiving encrypted data obtained by using any encryption method as claimed in claim 1-7; Generate target key data, wherein the target key data is obtained by intercepting the initial key data according to the length of a frame of the message to be encrypted; The encrypted data is decrypted according to the target key data to obtain the data to be encrypted.

9. The method according to claim 8, characterized in that The generating target key data comprises: A temporary session key is generated according to a synchronization message received from a CAN bus, wherein the temporary session key is the target key data.

10. The method according to claim 9, characterized in that The value carried by each synchronization message is self-increasing, where: The step of generating a temporary session key according to a synchronization message received from the CAN bus comprises: If it is verified that the temporary session key generated according to the first numerical value carried by the synchronization message cannot complete the decryption operation of the encrypted data, at least one numerical value close to the first numerical value is obtained, and the encrypted data is decrypted according to the at least one numerical value, wherein the at least one numerical value includes a number obtained by adding one or subtracting one from the first numerical value.

11. A data encryption device, characterized in that: The device comprises: An initial key data acquisition module is configured to acquire initial key data; A target key data generation module is configured to intercept and process the initial key data according to the length of a frame of the message to be encrypted to obtain target key data; An encryption module is configured to encrypt the message to be encrypted using the target key data to obtain encrypted data; A sending module, configured to send the encrypted data; The initial key data acquisition module is configured as follows: Generate a temporary session key using an encryption algorithm to obtain the initial key data, wherein the encryption algorithm is SM4 or AES encryption algorithm. The step of using an encryption algorithm to generate a temporary session key comprises: Assembling the first data and the second data to obtain 16-byte combined data, wherein the first data is a synchronization message transmitted on the CAN bus; and the second data is user-defined padding data; Encrypt the combined data using the key of SM4 to obtain the temporary session key; The assembling of the first data and the second data to obtain 16 bytes of combined data includes: Receiving the synchronization message transmitted through the CAN bus to obtain the first data; Acquire user-defined filling data as the second data; The synchronization message and the user-defined padding data are assembled into the combined data.

12. A data decryption device, characterized in that: The device comprises: A receiving module, configured to receive encrypted data obtained by using any encryption method according to claims 1-7; A target key generation module is configured to generate target key data, wherein the target key data is obtained by intercepting and processing the initial key data according to the length of a frame of the message to be encrypted; The decryption module is configured to decrypt the encrypted data according to the target key data to obtain the data to be encrypted.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method described in any one of claims 1 to 11 can be implemented.

14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method described in any one of claims 1 to 11 can be implemented.

Citation Information

Patent Citations

  • Code encryption and decryption methods and devices, computer device and storage medium

    CN108390759A

  • Encryption communication method of vehicle-mounted CAN bus message

    CN108494725A

  • TLS protocol session key restoration method based on random number implicit negotiation

    CN109600226A

  • Data encryption method and device, data decryption method and device and storage medium

    CN110401527A

  • Internet of Things terminal data safe receiving and sending system

    CN111245862A