Data encryption method and device based on symmetric key, data decryption method and device based on symmetric key, storage medium and electronic equipment
Patent Information
- Application Number
- CN202380015546.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2022-12-30
- Filing Date
- 2023-06-26
- Publication Date
- 2024-08-30
AI Technical Summary
Due to limitations in computing power and power consumption, IoT terminals cannot effectively use PKI-based asymmetric encryption algorithms, making it difficult to ensure data transmission security. Especially when establishing a secure connection, multiple communications are required and battery resources are consumed.
Using a data encryption method based on symmetric keys, it generates intermediate data, terminal integrity check data and session keys for encrypted transmission, reducing the use of symmetric keys, reducing data transmission volume and storage space occupation, and passing session serial numbers and The key is checked for integrity to prevent replay attacks.
With low computing and communication overhead, it ensures the security of data transmission, reduces the processing overhead and power consumption of terminal devices, and improves data transmission efficiency and security.
Smart Images

Figure CN118575443A
Abstract
Description
Data encryption method, data decryption method, device, storage medium and electronic device based on symmetric key Technical Field
[0001] The present application relates to the field of data security, and in particular to a data encryption method, a data decryption method, a device, a storage medium, and an electronic device based on a symmetric key. Background Art
[0002] With the development of the Internet of Things (IoT), a large number of terminals are connected to servers, exposing various sensitive data during transmission. This has led to significant data security issues. Ensuring security is essential for the development of the IoT. Technologies based on PKI (Public Key Infrastructure) are already widely used, but due to the computing power and power consumption limitations of IoT terminals, it's difficult to fully replicate PKI systems. The asymmetric encryption algorithms used by PKI are not well suited for small IoT terminals. In particular, PKI-based systems require multiple communications to establish a secure connection, and each communication requires carrying large amounts of data. IoT terminals are typically battery-powered, and PKI encryption algorithms consume significant amounts of battery.
[0003] Summary of the Invention
[0004] The present invention provides a data encryption method, data decryption method, device, storage medium, and electronic device based on a symmetric key, which can solve the problem of ensuring data transmission security with low computing and communication overhead. The technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a data encryption method based on a symmetric key, comprising:
[0006] Generate intermediate data according to the target data to be sent and the current session sequence number;
[0007] Generate terminal integrity verification data; wherein the terminal integrity verification data is generated according to a first hash digest, and the first hash digest is generated according to the length of the intermediate data, the device ID, and the intermediate data;
[0008] Encrypting the intermediate data and the terminal integrity data using a session key to obtain encrypted data;
[0009] Send a data packet carrying the device ID and the encrypted data to the server.
[0010] In one possible design, generating terminal integrity verification data includes:
[0011] Concatenate the length of the intermediate data, the device ID, the intermediate data, and a randomly generated salt value to obtain concatenated data;
[0012] Extracting a digest of the concatenated data using a hash function to obtain a first hash digest;
[0013] Generate terminal integrity verification data according to the first hash summary.
[0014] In one possible design, generating terminal integrity verification data according to the first hash digest includes:
[0015] All bytes, part of bytes, or calculations are performed on the intercepted bytes in the first hash digest to obtain the terminal integrity data.
[0016] In one possible design, it also includes:
[0017] Receive encrypted response data from the server;
[0018] Decrypting the encrypted response data using the stored session key to obtain intermediate response data, the current session sequence number, server integrity data, and original response data;
[0019] Compare the decrypted current session sequence number with the stored current session sequence number to see if they are the same;
[0020] If yes, generate server integrity check data according to the length of the decrypted intermediate response data, the device ID, and the decrypted intermediate response data;
[0021] Compare the generated server integrity verification data and the decrypted server integrity verification data to see if they are the same;
[0022] If yes, process the original response data obtained by decryption, and increment the stored current session sequence number by 1.
[0023] In one possible design, before generating the intermediate data according to the target data to be sent and the current session sequence number, the method further includes:
[0024] Generate and store terminal authentication random number, terminal session random number and terminal authentication serial number;
[0025] Send an authentication request message carrying the device ID, the terminal authentication random number Rac and the terminal authentication serial number Asnc to the server;
[0026] receiving an authentication response message carrying a server authentication digest and a server authentication random number from the server;
[0027] Calculating a server authentication digest based on the device ID, the stored terminal authentication random number, the received server authentication random number, the stored terminal authentication serial number, and the first salt value;
[0028] Comparing the calculated server authentication digest and the received server authentication digest to see if they are the same;
[0029] If yes, calculate the terminal authentication digest and terminal session random number ciphertext;
[0030] Sending an authentication confirmation message carrying the terminal authentication digest and the terminal session random number ciphertext to the server;
[0031] Receive server session random number ciphertext from the server;
[0032] The session key and current session sequence number are calculated and stored based on the received server session random number ciphertext, and the authentication success state is entered to prepare for sending the target data.
[0033] In a second aspect, the present embodiment provides a data decryption method based on a symmetric key, comprising:
[0034] Receive data packets carrying device ID and encrypted data from terminal devices;
[0035] Detecting the registration status and authentication status of the device ID;
[0036] If the state is registered and authenticated, the encrypted data is decrypted using the stored session key to obtain the intermediate data, the current session sequence number and the terminal integrity verification data;
[0037] Verify the legitimacy of the decrypted current session serial number;
[0038] If the verification is successful, generate terminal integrity verification data based on the length of the decrypted intermediate data, the device ID and the decrypted intermediate data;
[0039] Compare the generated terminal integrity verification data and the decrypted terminal integrity verification data to see if they are the same;
[0040] If yes, parse the decrypted intermediate data to obtain the current session sequence number and target data.
[0041] In one possible design, it also includes:
[0042] Generate raw response data;
[0043] generating intermediate response data according to the original response data and the stored current session sequence number;
[0044] Generate server integrity check data; wherein the server integrity check data is generated according to a second hash digest, and the second hash digest is generated according to the length of the intermediate response data, the device ID, and the intermediate response data;
[0045] Encrypting the intermediate response data and the server integrity check data using the stored session key to generate encrypted response data;
[0046] The encrypted response data is sent to the terminal device.
[0047] In one possible design, before receiving the data packet carrying the device ID and encrypted data from the terminal device, the method further includes:
[0048] Receive an authentication request message from a terminal device; wherein the authentication request message carries a device ID, a terminal authentication random number, and a terminal authentication serial number;
[0049] Detect whether the device ID is registered;
[0050] If yes, verify the legitimacy of the terminal authentication serial number;
[0051] If the verification is successful, generate and store the server authentication random number and server session random number corresponding to the device ID;
[0052] Calculate a server authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, the terminal authentication serial number, and a first salt value;
[0053] Sending an authentication response message carrying the server authentication digest and the server authentication random number to the terminal device;
[0054] Receiving an authentication confirmation message from the terminal device; wherein the authentication confirmation message carries a terminal authentication digest and a terminal session random number ciphertext;
[0055] Calculate a terminal authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, and a second salt value;
[0056] Comparing the calculated terminal authentication digest and the received terminal authentication digest to see if they are the same;
[0057] If yes, calculate the server session random number ciphertext and the terminal session random number;
[0058] Calculate and store the session key and current session sequence number;
[0059] The terminal device sends the calculated server session random number ciphertext.
[0060] In one possible design, verifying the legitimacy of the terminal authentication serial number includes:
[0061] When the terminal authentication serial number is a numeric serial number, if the terminal authentication serial number currently received is greater than the terminal authentication serial number received last time and is within a specified range, the verification is successful; or
[0062] When the terminal authentication serial number is a timestamp, if the time difference between the currently received terminal authentication serial number and the last received terminal authentication serial number is less than a deviation threshold, the verification is passed.
[0063] In a third aspect, an embodiment of the present application provides a data encryption device based on a symmetric key, comprising:
[0064] A generating unit, configured to generate intermediate data according to target data to be sent and a current session sequence number;
[0065] The generating unit is further configured to generate terminal integrity verification data; wherein the terminal integrity verification data is generated based on a first hash digest, and the first hash digest is generated based on a length of the intermediate data, a device ID, and the intermediate data;
[0066] an encryption unit, configured to encrypt the intermediate data and the terminal integrity data using a session key to obtain encrypted data;
[0067] The transceiver unit is configured to send a data packet carrying the device ID and the encrypted data to a server.
[0068] In a fourth aspect, an embodiment of the present application provides a data decryption device based on a symmetric key, comprising:
[0069] A transceiver unit, configured to receive data packets carrying a device ID and encrypted data from a terminal device;
[0070] a detection unit, configured to detect the registration status and authentication status of the device ID;
[0071] a decryption unit, configured to decrypt the encrypted data using the stored session key to obtain intermediate data, a current session sequence number, and terminal integrity verification data if the terminal is in a registered state or an authenticated state;
[0072] A verification unit, used to verify the legitimacy of the decrypted current session sequence number;
[0073] a generating unit, configured to generate terminal integrity verification data according to the length of the decrypted intermediate data, the device ID, and the decrypted intermediate data if the verification is successful;
[0074] a comparing unit, configured to compare the generated terminal integrity verification data and the decrypted terminal integrity verification data to see whether they are identical;
[0075] The parsing unit is configured to, if the answer is yes, parse the decrypted intermediate data to obtain the current session sequence number and target data.
[0076] In a fifth aspect, an embodiment of the present application provides a computer storage medium, which stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0077] In a sixth aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0078] The beneficial effects of the technical solutions provided by some embodiments of the present application include at least:
[0079] When data is transmitted between the terminal device and the server, symmetric keys are used to encrypt the original data. This eliminates the need to transmit and store bulky digital certificates during the encryption process, reducing data transmission and storage space, thereby lowering the processing overhead and power consumption of the terminal device. The session key and session sequence number are used to verify the integrity of the original data, ensuring data resistance to replay attacks. BRIEF DESCRIPTION OF THE DRAWINGS
[0080] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0081] FIG1 is a schematic diagram of a system architecture provided by an embodiment of the present application;
[0082] FIG2 is a schematic diagram of an interaction diagram of a symmetric key-based data transmission method provided in an embodiment of the present application;
[0083] FIG3 is an interactive diagram of the authentication process provided in an embodiment of the present application;
[0084] FIG4 is an interactive diagram of the registration process provided in an embodiment of the present application;
[0085] FIG5 is a schematic structural diagram of a digital encryption device based on a symmetric key provided by the present application;
[0086] FIG6 is a schematic diagram of the structure of a digital decryption device based on a symmetric key provided by the present application
[0087] FIG7 is a schematic structural diagram of an electronic device provided by the present application. DETAILED DESCRIPTION
[0088] In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
[0089] FIG1 shows a system architecture that can be applied to the present application, and the system architecture may include: a terminal device 10 and a server 11. The terminal device 10 and the server 11 may communicate with each other through a network, and the network is used as a medium for providing communication links between the above-mentioned units. The network may include various types of wired communication links or wireless communication links, for example: wired communication links include optical fibers, twisted pairs or coaxial cables, and wireless communication links include Bluetooth communication links, wireless fidelity (WIREless-FIdelity, Wi-Fi) communication links or microwave communication links. Among them, the terminal device 10 and the server 103 transmit data to each other in an encrypted manner.
[0090] It should be noted that the terminal device 10 and the server 11 can be hardware or software. When the terminal device 10 and the server 11 are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the terminal device 10 and the server 11 are software, they can be implemented as multiple software or software modules (for example, to provide distributed services), or as a single software or software module, without specific limitation herein.
[0091] The terminal device can be either hardware or software. When the terminal device is hardware, it can be various battery-powered IoT terminals, such as water meters, electricity meters, cameras, or other IoT devices. When the terminal device is software, it can be installed in the terminal devices listed above. It can be implemented as multiple software or software modules (for example, to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.
[0092] It should be understood that the number of terminal devices, networks, and servers in FIG1 is merely illustrative and can be any number of terminal devices, networks, and servers as required.
[0093] The following will introduce in detail the symmetric key-based data transmission method provided in the embodiment of the present application in conjunction with Figure 2. The transmission method in the embodiment of the present application is an interaction method between a terminal device and a server.
[0094] Please refer to Figure 2, which is a flowchart of a data transmission method based on a symmetric key according to an embodiment of the present application. As shown in Figure 2, the method according to the embodiment of the present application may include the following steps:
[0095] S201. The terminal device generates intermediate data according to the target data to be sent and the current session sequence number.
[0096] The terminal device can concatenate the target data to be sent and the current session sequence number into intermediate data by string concatenation. For example, if the target data to be sent is Bc0, let the intermediate data Bc = Snc||Bc0, where Snc is the current session sequence number of the terminal device and || represents byte string concatenation.
[0097] S202: The terminal device generates terminal integrity verification data.
[0098] Among them, the terminal integrity verification data is generated based on the first hash digest, for example: all bytes, partial bytes, multiple bytes XOR calculation, multiple bytes addition and subtraction calculation are performed on the first hash digest to obtain the terminal integrity verification data, the first hash digest is generated based on the length of the intermediate data, the device ID, the intermediate data and the salt value, for example: the generated terminal integrity verification data HBc = HASH(Len||ID||Bc||Salt7), HASH represents the hash function, Len represents the length of the intermediate data Bc, ID represents the device ID of the terminal, and Salt7 represents the randomly generated salt value.
[0099] S203: The terminal device generates encrypted data.
[0100] The encrypted data is generated by encrypting the intermediate data and terminal integrity check data using the stored session key. The session key is a symmetric key pre-calculated and stored by the terminal device. For example, the generated encrypted data DBc = ENC(Bc||HBc, Skey), where ENC represents the encryption function, Bc represents the intermediate data, HBc represents the terminal integrity check data, Skey represents the session key, and || represents byte string concatenation.
[0101] S204: The terminal device sends a data packet carrying the device ID and encrypted data to the server, and the server receives the data packet from the terminal device.
[0102] S205: The server parses the data packet to obtain the device ID and encrypted data, and detects the registration status and authentication status of the device ID.
[0103] S206: If the device ID is in a registered state and an authenticated state, the encrypted data is decrypted according to the stored session key to obtain the intermediate data, the current session sequence number and the terminal integrity verification data.
[0104] For example, the following method is used to decrypt the intermediate data Bc' = DEC(DBc, Skey), where DEC represents the decryption function, DBc represents the encrypted data from the terminal device, and Skey represents the session key calculated and stored by the server. This session key is the same as the session key stored by the terminal device. After decryption, the intermediate data, the current session sequence number, and the terminal integrity verification data are obtained.
[0105] If the device ID is in an unregistered or unauthenticated state, the data packet from the terminal device is discarded.
[0106] S207: The server verifies the legitimacy of the decrypted current session sequence number.
[0107] Among them, the method for verifying the legitimacy of the decrypted current session sequence number may include: comparing the decrypted current session sequence number Snc' with the previous session sequence number SncLast of the terminal device. If the current session sequence number Snc' is greater than or equal to the previous session sequence number SncLast, it means that the verification is successful, otherwise the verification fails.
[0108] If the decrypted current session sequence number Snc' is equal to the previous session sequence number SncLast, it means that the received data packet is a retransmitted data packet. If the decrypted current session sequence number is greater than the previous session sequence number, the received data packet is a new transmission data packet. If the decrypted current session sequence number is less than the previous session sequence number, it means that the received data packet is illegal and is discarded.
[0109] S208: If the verification is successful, the server generates terminal integrity verification data according to the length of the decrypted intermediate data, the received device ID, and the decrypted intermediate data.
[0110] Among them, the terminal integrity data generated by the server is expressed as HBc'=HASH(Len||ID||Bc'||Salt7); HASH is a hash function, Bc' represents the decrypted intermediate data, ID represents the device ID received by the server, Len represents the length of the decrypted intermediate data, and Salt7 represents a randomly generated salt value, which is the same as the salt value in S202.
[0111] S209: The server compares the generated terminal integrity verification data and the decrypted terminal integrity verification data to see if they are the same. If so, the server parses the decrypted intermediate data to obtain the current session sequence number and target data.
[0112] For example, parse and process Bc' to obtain the current session sequence number Snc' and the target data Bc0. If they are not the same, discard the received data packet.
[0113] S210: The server processes the target data and generates original response data.
[0114] For example: the generated original response data Ac0.
[0115] S211. The server generates intermediate response data according to the original response data and the stored current session sequence number.
[0116] Among them, the server can use string concatenation to concatenate the original response data and the stored current session sequence number into intermediate response data, for example: intermediate response data Ac = Snc'||Ac0. Since the above integrity check is passed, the current session sequence number Snc' stored by the server here should be the same as the current session sequence number Snc stored by the terminal device.
[0117] S212: The server generates server integrity verification data.
[0118] Among them, the server integrity verification data is generated based on the second hash digest, for example: all bytes, partial bytes, multiple bytes XOR calculation, multiple bytes addition and subtraction calculation are used to obtain the server integrity verification data, and the second hash digest is generated based on the length of the intermediate response data, the device ID, the intermediate response data and the salt value, for example: the generated server integrity verification data HAc = HASH (Len||ID||Ac||Salt 8), HASH represents the hash function, Len represents the length of the intermediate response data Ac, ID represents the device ID of the terminal, and Salt 8 represents the randomly generated salt value.
[0119] S213. The server generates encrypted response data.
[0120] Among them, the server uses the stored session key to encrypt the server integrity verification data and the intermediate response data to generate response encrypted data, for example: DAc = ENC(Ac||HAc, Skey), DAc represents the generated response encrypted data, Ac represents the intermediate response data, HAc represents the server integrity verification data, Skey represents the session key stored by the server, and || represents string splicing.
[0121] S214. The server sends the encrypted response data to the terminal device, and the terminal device receives the encrypted response data from the server.
[0122] S215. The terminal device uses the stored session key to decrypt the received encrypted response data to obtain the intermediate response data, the current session sequence number, the server integrity check data, and the original response data.
[0123] For example, the intermediate response data Ac'=DEC(DAc, Skey) is decrypted in the following manner, and Ac'=Snc'||Ac0' and the server integrity check data HAc are extracted from the decrypted intermediate response data Ac'.
[0124] S216. The terminal device compares the decrypted current session sequence number with the stored current session sequence number to see if they are the same. If so, the terminal device generates server integrity verification data based on the length of the decrypted intermediate response data, the device ID, and the decrypted intermediate response data.
[0125] For example, the server integrity check data HAc' = HASH(Len||ID||Ac'||Salt8) is generated as follows, where Len is the length of the decrypted intermediate response data Ac', HASH represents the hash function, ID represents the device identifier of the terminal device, and Salt8 represents the generated random number, which is the same as the salt value in S212. If the decrypted current session sequence number is different from the stored current session sequence number, the data is invalid and the encrypted response data from the server is discarded.
[0126] S217. The terminal device compares the generated server integrity verification data and the decrypted server integrity verification data to see if they are the same. If so, the terminal device processes the decrypted original response data and increases the stored current session sequence number by 1.
[0127] If they are not the same, it indicates that there is a problem with the integrity check and the encrypted response data from the server is discarded. When the terminal device sends the target data again, it continues to send data using the updated current session sequence number.
[0128] In some embodiments of the present application, a server may be composed of multiple different servers, each of which performs different steps. The specific steps performed can be determined based on actual needs and are not limited by this application. For example, the server may be composed of a communication server and a security server. The communication server is used to receive and send data, while the security server performs data processing, such as verification, encryption, and decryption. By deploying a server cluster, the processing overhead of each server is balanced, thereby improving server processing efficiency.
[0129] Among them, although steps S201 to S217 disclose the process of the terminal device encrypting the target data and sending the encrypted data to the server, the server can also use the above steps to encrypt the target data and send the encrypted data to the terminal device, but use different session numbers. The specific process will not be repeated here.
[0130] In some embodiments of the present application, the terminal device may perform an authentication process before sending target data to the server. The authentication process may refer to the steps shown in FIG3 :
[0131] S301. The terminal device generates and stores a terminal authentication random number, a terminal session random number, and a terminal authentication serial number.
[0132] The terminal device generates and stores a terminal authentication random number Rac and a terminal session random number Rsc. The length of the session random number Rsc can be determined based on actual needs and is not limited by this application. The terminal device generates a terminal authentication serial number Asnc, which can be a serial number stored when the terminal device is registered or a timestamp.
[0133] S302: The terminal device sends an authentication request message to the server, and the server receives the authentication request message from the terminal device.
[0134] The authentication request message carries the device ID, the terminal authentication random number Rac, and the terminal authentication serial number Asnc.
[0135] S303: The server parses the authentication request message and checks whether the device ID is registered.
[0136] Among them, the server parses the authentication request message to obtain the device ID, terminal authentication random number Rac and terminal authentication serial number Asnc, and determines whether the device ID is in the registration database. If so, it is determined that the device ID is registered. Otherwise, the device ID is not registered, and the authentication request message is determined to be an illegal request. The server then discards the authentication request message and optionally returns an authentication failure message to the terminal device.
[0137] S304: If yes, the server verifies the legitimacy of the terminal authentication serial number.
[0138] Among them, the process of the server verifying the legitimacy of the received terminal authentication serial number can be: when the terminal authentication serial number is a digital serial number, the server compares whether the terminal authentication serial number currently received is greater than the terminal authentication serial number stored last time and is within the specified range. If so, the verification is successful; otherwise, the verification fails, and the authentication request message is determined to be an illegal request, then the authentication request message is discarded and an authentication failure message is returned to the terminal device; when the terminal authentication serial number is a timestamp, the server compares the time difference between the terminal authentication serial number currently received and the terminal authentication serial number stored last time. If the time difference is less than the specified deviation threshold, the verification is successful; otherwise, the verification fails, and the authentication request message is determined to be an illegal request, then the authentication request message is discarded and an authentication failure message is returned to the terminal device.
[0139] S305: The server generates and stores a server authentication random number and a server session random number for the device ID.
[0140] If the verification is successful, the server generates and stores a server authentication random number Ras for the device ID, and generates and stores a server session random number Rss.
[0141] S306. The server calculates the server authentication digest.
[0142] Among them, the server authentication digest is generated based on the third hash digest. For example, all characters, part of the characters, or the intercepted characters can be intercepted from the third hash digest to obtain the server authentication digest. The generation of the third hash digest includes: using the original key to encrypt the device ID, terminal authentication random number, server authentication random number, terminal authentication serial number, and salt value, and then using the hash digest algorithm to process the encrypted data to obtain the third hash digest.
[0143] For example: Generate the server authentication summary Has=HASH(ENC(ID||Rac||Ras||Asnc,Key)||Salt1) according to the following method, where ENC represents the encryption function, Key represents the original key generated when the terminal device registers using the device ID, which is a symmetric key. Both the server and the terminal device store the original key, ID represents the device ID, Rac represents the received terminal authentication random number, Ras represents the stored server authentication random number, Asnc represents the received terminal authentication serial number, || represents string concatenation, and Salt1 represents the randomly generated salt value.
[0144] S307: The server sends an authentication response message carrying the server authentication digest and the server authentication random number to the terminal device, and the terminal device receives the authentication response message from the server.
[0145] For example, the server sends an authentication response message composed of the server authentication digest Has and the server authentication random number Ras to the terminal device, and the device parses the authentication response message to obtain the server authentication digest Has and the server authentication random number Ras.
[0146] S308. The terminal device calculates the server authentication digest according to the device ID, the terminal authentication random number, the received server authentication random number and the terminal authentication serial number.
[0147] For example: the server authentication summary Has'=HASH(ENC(ID||Rac||Ras||Asnc,Key)||Salt 1) is calculated according to the following method; HASH is a hash function, ENC is an encryption function, ID is the device ID of the terminal device, Rac is the authentication random number generated by the terminal device, Ras is the server authentication random number received by the terminal device, Asnc represents the terminal authentication serial number generated by the terminal device, Key represents the original key generated when the terminal device is registered, and Salt 1 is the same as the salt value in S305.
[0148] S309: The terminal device compares the calculated server authentication digest with the received server authentication digest to see if they are the same.
[0149] If the answer is yes, the terminal device successfully authenticates the server. If the answer is no, the terminal device fails to authenticate the server and re-initiates authentication after a preset delay.
[0150] For example, the terminal device compares the server authentication digest Has' calculated by itself with the server authentication digest Has sent by the server. If the two are the same, the server authentication is successful and the next step is performed. Otherwise, the authentication is re-initiated after a delay of 5 seconds.
[0151] S310: If they are the same, the terminal device calculates the terminal authentication digest.
[0152] The terminal authentication digest is generated based on the fourth digest. The terminal authentication digest is obtained by intercepting all characters, intercepting some characters, or calculating the intercepted characters in the fourth digest. The fourth digest is generated based on the encrypted data, which is generated using the original key for the device ID, the terminal authentication random number, the server authentication random number, and the terminal authentication serial number. For example, the terminal authentication digest is generated according to the following formula: HAc = HASH(ENC(ID||Rac||Ras||Asnc, Key)||Salt2), where HAc is the calculated terminal authentication digest, HASH is the hash function, ENC is the encryption function, ID is the device ID, Rac is the terminal authentication random number, Ras is the received server authentication random number, Asnc is the terminal authentication serial number, Key is the original key, Salt2 is the generated random number, and || represents character concatenation.
[0153] S311. The terminal device calculates the terminal session random number ciphertext.
[0154] Among them, the method for calculating the terminal session random number ciphertext can be: using the original key to encrypt the device ID, terminal authentication random number, server authentication random number and terminal authentication serial number, and then using the digest algorithm to calculate the encrypted data to obtain a digest, and generating the terminal session random number ciphertext based on the digest and the terminal session random number.
[0155] For example, the terminal device uses the following formula to calculate the terminal session random number ciphertext Xsc = Rsc XOR HASH(ENC(ID||Rac||Ras||Asnc, Key)||Salt3), where ENC represents the encryption function, XOR represents the exclusive OR operation, Rsc represents the terminal session random number, ID represents the device ID, Rac represents the terminal authentication random number, Ras represents the server authentication random number, Asnc represents the terminal authentication serial number, and Salt3 represents the generated random number.
[0156] S312: The terminal device sends an authentication confirmation message carrying the terminal authentication digest and the terminal session random number ciphertext to the server, and the server receives the authentication confirmation message from the terminal device.
[0157] S313. The server calculates the terminal authentication summary.
[0158] The server calculates the terminal authentication digest using the same method as S309, for example: the server calculates the terminal authentication digest HAc'=HASH(ENC(ID||Rac||Ras||Asnc, Key)||Salt2), where Rac is the terminal authentication random number received from the terminal device, and Asnc is the terminal authentication serial number received from the terminal device.
[0159] S314: The server compares the calculated terminal authentication digest with the received terminal authentication digest to see if they are the same.
[0160] The server compares its own calculated terminal authentication digest HAc' with the terminal authentication digest HAc sent by the terminal device to see if they are the same. If they are the same, the terminal authentication is successful. If they are not the same, the authentication confirmation message is discarded.
[0161] S315: If yes, the server calculates the server session random number ciphertext.
[0162] The server calculates the server session random number ciphertext Xss=Rss XOR HASH(ENC(ID||Rac||Ras||Asnc,Key)||Salt4), where Salt4 is the generated random number.
[0163] S316: The server calculates a random number for the terminal session.
[0164] The server calculates and obtains the terminal session random number Rsc′=Xsc XOR HASH(ENC(ID||Rac||Ras||Asnc,Key)||Salt 3).
[0165] S317. The server calculates and stores the session key and the current session sequence number.
[0166] Among them, the server calculates and stores: session key SKey = HASH (Rsc'||Rss||Asnc||Salt 5), current session sequence number Snc||Sns = HASH (Rsc||Rss'||Asnc||Salt 6), Snc and Sns can be respectively extracted from all or part of the bytes of the digest, Snc represents the session sequence number initiated by the terminal device, and Sns represents the session sequence number initiated by the server. For example: the terminal device reads sensor data and actively sends it to the server using Snc=a, and the server uses the same Snc=a when responding to the terminal device after receiving the sensor data; the server uses Sns=b to actively send a control command to the terminal device to turn on the fan to which it is connected, and the terminal device also uses Sns=b to send response data after receiving the control command.
[0167] S318. The server sends the server session random number ciphertext to the terminal device, and the terminal device receives the server session random number ciphertext from the server.
[0168] The server sends the server session random number ciphertext Xss to the terminal device.
[0169] S319. The terminal device calculates a random number for the server session.
[0170] The terminal device calculates and obtains the server session random number Rss'=Xss XOR HASH(ENC(ID||Rac||Ras||Asnc,Key)||Salt 4).
[0171] S320: The terminal device calculates and stores the session key and the current session sequence number.
[0172] The terminal device calculates and stores the following: session key SKey = HASH(Rsc||Rss'||Asnc||Salt5) and current session sequence number Snc||Sns = HASH(Rsc||Rss'||Asnc||Salt6). Because the same digest is used as the server, the session key and sequence number calculated by the terminal device are exactly the same as those calculated by the server.
[0173] S321: The terminal device enters the authentication success state and prepares to send the target data.
[0174] Figure 3 describes the use of a four-way handshake to achieve identity authentication between the terminal device and the server. This application can also use a three-way handshake to achieve identity authentication. The specific improvement is: in the second handshake communication in Figure 3, the session random number of the fourth handshake communication can be sent.
[0175] Optionally, in some embodiments of the present application, intermediate data is padded, including the target data length, device ID, session sequence number, and target data to be sent. The data is first encrypted using the session key, and then the encryption result is processed using a digest algorithm to obtain integrity data. If necessary, the digest result can be reduced to a shorter, appropriate length using a multi-byte XOR calculation. The integrity data can be directly appended to the data packet for transmission, or it can be encrypted again along with the target data to be sent.
[0176] Furthermore, the present application may use the original key to encrypt the original intermediate block instead of using the session key for encryption.
[0177] The session sequence number used in this application can also be implemented in the following four ways:
[0178] 1. Use the concatenation of some bytes of the digest algorithm result of the session key, or generate it through a multi-byte exclusive-or operation; or
[0179] 2. Use the byte concatenation of the session nonce, or generate it by XORing its multiple bytes; or
[0180] 3. Generated by performing a byte-wise XOR operation on the digest algorithm result of the authentication number and the session key (session random number); or
[0181] 4. Use the authentication random number and any combination of the data in 1, 2, and 3 to perform an XOR operation or a digest;
[0182] Among them, any combination of the above 4 methods and implementation methods.
[0183] In some embodiments of the present application, before performing the authentication process between the terminal device and the server, a registration process may also be performed. The registration process includes the following steps:
[0184] S401: The terminal device generates a device ID and a current terminal authentication serial number.
[0185] The device ID represents the unique identity of the terminal device, and the current terminal authentication serial number can be generated by adding 1 to the stored terminal authentication serial number, or by using the current timestamp.
[0186] S402: The terminal device sends a registration request message carrying the device ID and the current terminal authentication serial number to the server, and the server receives the registration request message from the terminal device.
[0187] S403: The server generates an original key and stores the current terminal authentication serial number and device ID.
[0188] S404: The server sends a registration response message carrying the original key to the terminal device, and the terminal device receives the registration response message from the server.
[0189] The terminal device parses the registration response message to obtain the original key and stores the original key.
[0190] The embodiments of the present application have the following beneficial effects:
[0191] 1) It uses symmetric encryption and digest algorithms, eliminating the need for asymmetric implementations. It only uses symmetric keys and eliminates the need for bulky certificates. The authentication and key exchange process requires only four communications (which can be further reduced to three), resulting in high speed.
[0192] 2) During the authentication and key exchange processes, the original key is not used to encrypt data directly, but its digest result is used, which is more secure.
[0193] 3) Using the authentication serial number ensures that the data exchanged during each authentication process is not repeated. Even if one party uses the same random number, there will be no problem of reduced security.
[0194] 4) Using session keys and session numbers, the integrity of the data can be verified and the data can be protected against replay attacks.
[0195] The following are device embodiments of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0196] Please refer to Figure 5, which shows a schematic diagram of the structure of a symmetric key-based data encryption device provided by an exemplary embodiment of the present application, hereinafter referred to as device 5. Device 5 can be implemented as all or part of a terminal device through software, hardware, or a combination of both. Device 5 includes: a generation unit 501, an encryption unit 502, and a transceiver unit 503.
[0197] A generating unit 501 is configured to generate intermediate data according to the target data to be sent and the current session sequence number;
[0198] The generating unit 501 is further configured to generate terminal integrity verification data; wherein the terminal integrity verification data is generated based on a first hash digest, which is generated based on a length of the intermediate data, a device ID, and the intermediate data;
[0199] An encryption unit 502 is configured to encrypt the intermediate data and the terminal integrity data using a session key to obtain encrypted data;
[0200] The transceiver unit 503 is configured to send a data packet carrying the device ID and the encrypted data to the server.
[0201] In one or more possible embodiments, generating terminal integrity verification data includes:
[0202] Concatenate the length of the intermediate data, the device ID, the intermediate data, and a randomly generated salt value to obtain concatenated data;
[0203] Extracting a digest of the concatenated data using a hash function to obtain a first hash digest;
[0204] Generate terminal integrity verification data according to the first hash summary.
[0205] In one or more possible embodiments, generating terminal integrity verification data according to the first hash digest includes:
[0206] All bytes, part of bytes, or calculations are performed on the intercepted bytes in the first hash digest to obtain the terminal integrity data.
[0207] In one or more possible embodiments, it further includes:
[0208] A response unit, configured to receive encrypted response data from a server;
[0209] Decrypting the encrypted response data using the stored session key to obtain intermediate response data, the current session sequence number, server integrity data, and original response data;
[0210] Compare the decrypted current session sequence number with the stored current session sequence number to see if they are the same;
[0211] If yes, generate server integrity check data according to the length of the decrypted intermediate response data, the device ID, and the decrypted intermediate response data;
[0212] Compare the generated server integrity verification data and the decrypted server integrity verification data to see if they are the same;
[0213] If yes, process the original response data obtained by decryption, and increment the stored current session sequence number by 1.
[0214] In one or more possible embodiments, it further includes:
[0215] An authentication unit, configured to generate and store a terminal authentication random number, a terminal session random number, and a terminal authentication serial number;
[0216] Send an authentication request message carrying the device ID, the terminal authentication random number Rac and the terminal authentication serial number Asnc to the server;
[0217] receiving an authentication response message carrying a server authentication digest and a server authentication random number from the server;
[0218] Calculating a server authentication digest based on the device ID, the stored terminal authentication random number, the received server authentication random number, the stored terminal authentication serial number, and the first salt value;
[0219] Comparing the calculated server authentication digest and the received server authentication digest to see if they are the same;
[0220] If yes, calculate the terminal authentication digest and terminal session random number ciphertext;
[0221] Sending an authentication confirmation message carrying the terminal authentication digest and the terminal session random number ciphertext to the server;
[0222] Receive server session random number ciphertext from the server;
[0223] The session key and current session sequence number are calculated and stored based on the received server session random number ciphertext, and the authentication success state is entered to prepare for sending the target data.
[0224] It should be noted that the device 5 provided in the above embodiment, when executing the symmetric key-based data encryption method, only uses the division of the above-mentioned functional modules as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the above-mentioned functions. In addition, the symmetric key-based data encryption device provided in the above embodiment and the symmetric key-based data encryption method embodiment are based on the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.
[0225] Please refer to Figure 6, which shows a schematic diagram of the structure of a symmetric key-based data decryption device provided by an exemplary embodiment of the present application, hereinafter referred to as device 6. Device 6 can be implemented as all or part of a server through software, hardware, or a combination of both. Device 6 includes a transceiver unit 601, a detection unit 602, a decryption unit 603, a verification unit 604, a generation unit 605, a comparison unit 606, and a parsing unit 607.
[0226] The transceiver unit 601 is used to receive a data packet carrying a device ID and encrypted data from a terminal device;
[0227] A detection unit 602 is used to detect the registration status and authentication status of the device ID;
[0228] A decryption unit 603 is configured to decrypt the encrypted data using the stored session key to obtain intermediate data, a current session sequence number, and terminal integrity verification data if the terminal is in a registered state or an authenticated state;
[0229] Verification unit 604, used to verify the legitimacy of the decrypted current session sequence number;
[0230] A generating unit 605 is configured to generate terminal integrity verification data according to the length of the decrypted intermediate data, the device ID, and the decrypted intermediate data if the verification is successful;
[0231] A comparing unit 606 is configured to compare the generated terminal integrity verification data with the decrypted terminal integrity verification data to determine whether they are identical;
[0232] The parsing unit 607 is configured to, if yes, parse the decrypted intermediate data to obtain the current session sequence number and target data.
[0233] In one or more possible embodiments, it further includes:
[0234] A response unit, configured to generate original response data;
[0235] generating intermediate response data according to the original response data and the stored current session sequence number;
[0236] Generate server integrity check data; wherein the server integrity check data is generated according to a second hash digest, and the second hash digest is generated according to the length of the intermediate response data, the device ID, and the intermediate response data;
[0237] Encrypting the intermediate response data and the server integrity check data using the stored session key to generate encrypted response data;
[0238] The encrypted response data is sent to the terminal device.
[0239] In one or more possible embodiments, it further includes:
[0240] An authentication unit, configured to receive an authentication request message from a terminal device; wherein the authentication request message carries a device ID, a terminal authentication random number, and a terminal authentication serial number;
[0241] Detect whether the device ID is registered;
[0242] If yes, verify the legitimacy of the terminal authentication serial number;
[0243] If the verification is successful, generate and store the server authentication random number and server session random number corresponding to the device ID;
[0244] Calculate a server authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, the terminal authentication serial number, and a first salt value;
[0245] Sending an authentication response message carrying the server authentication digest and the server authentication random number to the terminal device;
[0246] Receiving an authentication confirmation message from the terminal device; wherein the authentication confirmation message carries a terminal authentication digest and a terminal session random number ciphertext;
[0247] Calculate a terminal authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, and a second salt value;
[0248] Comparing the calculated terminal authentication digest and the received terminal authentication digest to see if they are the same;
[0249] If yes, calculate the server session random number ciphertext and the terminal session random number;
[0250] Calculate and store the session key and current session sequence number;
[0251] The terminal device sends the calculated server session random number ciphertext.
[0252] In one or more possible embodiments, verifying the legitimacy of the terminal authentication serial number includes:
[0253] When the terminal authentication serial number is a digital serial number, if the terminal authentication serial number currently received is greater than the terminal authentication serial number received last time, the verification is successful; or
[0254] When the terminal authentication serial number is a timestamp, if the time difference between the currently received terminal authentication serial number and the last received terminal authentication serial number is less than a deviation threshold, the verification is passed.
[0255] It should be noted that the device 6 provided in the above embodiment, when executing the data decryption method based on a symmetric key, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the above functions. In addition, the data decryption device based on a symmetric key provided in the above embodiment and the data decryption method based on a symmetric key are of the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.
[0256] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0257] An embodiment of the present application also provides a computer storage medium, which can store multiple instructions. The instructions are suitable for being loaded by a processor and executing the method steps of the embodiments shown in Figures 2 to 4 above. The specific execution process can be found in the specific description of the embodiments shown in Figures 2 to 4, and will not be repeated here.
[0258] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the symmetric key-based data transmission method described in the above embodiments.
[0259] Please refer to Figure 7, which shows a schematic diagram of the structure of an electronic device according to an embodiment of the present application. The electronic device may be the terminal device or the electronic device shown in Figure 1. As shown in Figure 7, the electronic device 700 may include: at least one processor 701, at least one network interface 704, a memory 703, and at least one communication bus 702.
[0260] The communication bus 702 is used to implement the connection and communication between these components.
[0261] When the electronic device is a terminal device, it also includes a user interface (not shown in FIG. 7 ), which is used to implement human-computer interaction and includes but is not limited to an input unit and a display unit.
[0262] The network interface 704 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface) for communicating with the control device.
[0263] The processor 701 may include one or more processing cores. The processor 701 utilizes various interfaces and circuits to connect the various components within the entire electronic device 700. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 703, and calling data stored in the memory 703, the processor 701 performs various functions of the electronic device 700 and processes data. Optionally, the processor 701 may be implemented in the form of at least one hardware component selected from the group consisting of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 701 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is responsible for handling wireless communications. It is understood that the modem may not be integrated into the processor 701 and may be implemented separately on a single chip.
[0264] Among them, the memory 703 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 703 includes a non-transitory computer-readable storage medium. The memory 703 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 703 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 703 may also be at least one storage device located away from the aforementioned processor 701. As shown in Figure 7, the memory 703 as a computer storage medium may include an operating system, a network communication module, a user interface module and an application.
[0265] In the electronic device 700 shown in FIG7 , the processor 701 can be used to call the application stored in the memory 703 and specifically execute the method shown in FIG2 to FIG4 . The specific process can be referred to as shown in FIG2 to FIG4 and will not be repeated here.
[0266] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing related hardware through a computer program. The program can be stored in a computer-readable storage medium, and when executed, the program can include the processes in the above-described method embodiments. The storage medium can be a magnetic disk, an optical disk, a read-only memory, or a random access memory.
[0267] The above disclosure is only a preferred embodiment of the present application, and certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A data encryption method based on a symmetric key, characterized in that: include: Generate intermediate data according to the target data to be sent and the current session sequence number; Generate terminal integrity verification data; wherein the terminal integrity verification data is generated according to a first hash digest, and the first hash digest is generated according to the length of the intermediate data, the device ID, and the intermediate data; Encrypting the intermediate data and the terminal integrity data using a session key to obtain encrypted data; Send a data packet carrying the device ID and the encrypted data to the server.
2. The method according to claim 1, characterized in that Generating terminal integrity verification data includes: Concatenate the length of the intermediate data, the device ID, the intermediate data, and a randomly generated salt value to obtain concatenated data; Extracting a digest of the concatenated data using a hash function to obtain a first hash digest; Generate terminal integrity verification data according to the first hash summary.
3. The method according to claim 2, characterized in that Generating terminal integrity verification data according to the first hash digest includes: All bytes, part of bytes, or calculations are performed on the intercepted bytes in the first hash digest to obtain the terminal integrity data.
4. The method according to claim 1, 2 or 3, characterized in that: Also includes: Receive encrypted response data from the server; Decrypting the encrypted response data using the stored session key to obtain intermediate response data, the current session sequence number, server integrity data, and original response data; Compare the decrypted current session sequence number with the stored current session sequence number to see if they are the same; If yes, generate server integrity check data according to the length of the decrypted intermediate response data, the device ID, and the decrypted intermediate response data; Compare the generated server integrity verification data and the decrypted server integrity verification data to see if they are the same; If yes, process the original response data obtained by decryption, and increment the stored current session sequence number by 1.
5. The method according to claim 4, characterized in that Before generating intermediate data according to the target data to be sent and the current session sequence number, the method further includes: Generate and store terminal authentication random number, terminal session random number and terminal authentication serial number; Send an authentication request message carrying the device ID, the terminal authentication random number Rac and the terminal authentication serial number Asnc to the server; receiving an authentication response message carrying a server authentication digest and a server authentication random number from the server; Calculating a server authentication digest based on the device ID, the stored terminal authentication random number, the received server authentication random number, the stored terminal authentication serial number, and the first salt value; Comparing the calculated server authentication digest and the received server authentication digest to see if they are the same; If yes, calculate the terminal authentication digest and terminal session random number ciphertext; Sending an authentication confirmation message carrying the terminal authentication digest and the terminal session random number ciphertext to the server; Receive server session random number ciphertext from the server; The session key and current session sequence number are calculated and stored based on the received server session random number ciphertext, and the authentication success state is entered to prepare for sending the target data.
6. A data decryption method based on a symmetric key, characterized in that: include: Receive data packets carrying device ID and encrypted data from terminal devices; Detecting the registration status and authentication status of the device ID; If the state is registered and authenticated, the encrypted data is decrypted using the stored session key to obtain the intermediate data, the current session sequence number and the terminal integrity verification data; Verify the legitimacy of the decrypted current session serial number; If the verification is successful, generate terminal integrity verification data based on the length of the decrypted intermediate data, the device ID and the decrypted intermediate data; Compare the generated terminal integrity verification data and the decrypted terminal integrity verification data to see if they are the same; If yes, parse the decrypted intermediate data to obtain the current session sequence number and target data.
7. The method according to claim 6, characterized in that Also includes: Generate raw response data; generating intermediate response data according to the original response data and the stored current session sequence number; Generate server integrity check data; wherein the server integrity check data is generated according to a second hash digest, and the second hash digest is generated according to the length of the intermediate response data, the device ID, and the intermediate response data; Encrypting the intermediate response data and the server integrity check data using the stored session key to generate encrypted response data; The encrypted response data is sent to the terminal device.
8. The method according to claim 6 or 7, characterized in that Before receiving the data packet carrying the device ID and encrypted data from the terminal device, the method further includes: Receive an authentication request message from a terminal device; wherein the authentication request message carries a device ID, a terminal authentication random number, and a terminal authentication serial number; Detect whether the device ID is registered; If yes, verify the legitimacy of the terminal authentication serial number; If the verification is successful, generate and store the server authentication random number and server session random number corresponding to the device ID; Calculate a server authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, the terminal authentication serial number, and a first salt value; Sending an authentication response message carrying the server authentication digest and the server authentication random number to the terminal device; Receiving an authentication confirmation message from the terminal device; wherein the authentication confirmation message carries a terminal authentication digest and a terminal session random number ciphertext; Calculate a terminal authentication digest based on the stored original key, the device ID, the terminal authentication random number, the server authentication random number, and a second salt value; Comparing the calculated terminal authentication digest and the received terminal authentication digest to see if they are the same; If yes, calculate the server session random number ciphertext and the terminal session random number; Calculate and store the session key and current session sequence number; The terminal device sends the calculated server session random number ciphertext.
9. The method according to claim 8, characterized in that The verification of the legitimacy of the terminal authentication serial number includes: When the terminal authentication serial number is a numeric serial number, if the terminal authentication serial number currently received is greater than the terminal authentication serial number received last time and is within a specified range, the verification is successful; or When the terminal authentication serial number is a timestamp, if the time difference between the currently received terminal authentication serial number and the last received terminal authentication serial number is less than a deviation threshold, the verification is passed.
10. A data encryption device based on a symmetric key, characterized in that: include: A generating unit, configured to generate intermediate data according to target data to be sent and a current session sequence number; The generating unit is further configured to generate terminal integrity verification data; wherein the terminal integrity verification data is generated based on a first hash digest, and the first hash digest is generated based on a length of the intermediate data, a device ID, and the intermediate data; an encryption unit, configured to encrypt the intermediate data and the terminal integrity data using a session key to obtain encrypted data; The transceiver unit is configured to send a data packet carrying the device ID and the encrypted data to a server.
11. A data decryption device based on a symmetric key, characterized in that: include: A transceiver unit, configured to receive data packets carrying a device ID and encrypted data from a terminal device; a detection unit, configured to detect the registration status and authentication status of the device ID; a decryption unit, configured to decrypt the encrypted data using the stored session key to obtain intermediate data, a current session sequence number, and terminal integrity verification data if the terminal is in a registered state or an authenticated state; A verification unit, used to verify the legitimacy of the decrypted current session sequence number; a generating unit, configured to generate terminal integrity verification data according to the length of the decrypted intermediate data, the device ID, and the decrypted intermediate data if the verification is successful; a comparing unit, configured to compare the generated terminal integrity verification data and the decrypted terminal integrity verification data to see whether they are identical; The parsing unit is configured to, if the answer is yes, parse the decrypted intermediate data to obtain the current session sequence number and target data.
12. A computer storage medium, characterized in that The computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 9.
13. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps according to any one of claims 1 to 9.
