End-to-end encrypted data key distribution method, electronic device and program product
By randomly generating session keys on the client and encrypting with the server-side public key, the problem of insufficient end-to-end communication security in the prior art is solved, efficient data key distribution and storage is achieved, and communication security is significantly improved.
Patent Information
- Application Number
- CN202510349547.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-05-13
AI Technical Summary
In the prior art, end-to-end communication is insufficient security, and hard-coded data keys are easily retrieved by attackers in reverse, resulting in communication data leakage.
The session key is generated by randomly generating the session key on the client and encrypting the key using the server's public key, and the session key ciphertext is generated. The client sends the session key ciphertext to the server, which decrypts and generates a data key using the private key, encrypts the data key and timestamps using the session key, and sends it to the client to store.
It greatly improves the security of end-to-end communication, reduces the computing and storage burden on the server, prevents data keys from being reversely acquired, and ensures the security of communication data.
Smart Images

Figure CN119995879A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer and communication technology, and in particular to a method for distributing end-to-end encrypted data keys, electronic equipment and program products. Background Art
[0002] End-to-End Encryption (E2EE) is a technology that ensures that data remains private and secure between communicating parties. Its core concept is that only the sender and receiver can decrypt the message, ensuring that it cannot be read by a third party even if it is intercepted during transmission. Through end-to-end encryption, even if an attacker bypasses the https protocol, sensitive fields can be guaranteed not to be stolen due to encryption, greatly improving the security of data transmission.
[0003] In real-world application scenarios, the client may be running a web application, an app, or a small program. Designers often hardcode the data key into the front-end code, which is used to encrypt and decrypt communications with the server. During the hard-coding process, obfuscation technology is used to conceal the logic of the front-end code, or the wasm method (code compiled into a binary instruction format) is used to improve code security. However, js code obfuscation and the wasm method cannot fundamentally prevent attackers from reversely obtaining key information. Therefore, once the attacker obtains the key, the communication data between the client and the server will be obtained. In addition, since the hard-coding method is to hard-code the data key into the front-end code, multiple users use the same data key in different sessions. Once the attacker obtains the data key, all client communication history and all future communication information can be decrypted, and the communication security is extremely poor. Summary of the invention
[0004] The present invention provides an end-to-end encrypted data key distribution method, electronic device and program product, which are used to solve the defects of end-to-end communication security in the prior art, greatly improve the security of end-to-end communication, and reduce the computing and storage burden of the server.
[0005] The present invention provides a data key distribution method for end-to-end encryption applied to a client, comprising the following steps: in response to the absence of a valid data key in a memory, randomly generating a session key; encrypting first data using a public key of a server to obtain a session key ciphertext; wherein the first data includes the session key; generating a first type of request information and sending it to the server, wherein the first type of request information includes the session key ciphertext; wherein after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to a current first timestamp, a client identity and a master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends a first type of response information to the client, wherein the first type of response information includes the data key ciphertext; receives the first type of response information, and parses the data key ciphertext according to the first type of response information; decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0006] According to an end-to-end encrypted data key distribution method provided by the present invention, the first data also includes a second timestamp when the first data is encrypted; after the server executes the decryption of the session key ciphertext using the private key, it also obtains the second timestamp and verifies the timeliness of the first type of request information based on the second timestamp.
[0007] According to a method for distributing end-to-end encrypted data keys provided by the present invention, before generating a first type of request information and sending it to the server, the method further includes: using the session key to encrypt the first client sensitive data to obtain the first client data ciphertext, and the first type of request information also includes the first client data ciphertext; wherein, after receiving the first type of request information, the server also obtains the first client data ciphertext, decrypts the first client data ciphertext using the session key to obtain the first client sensitive data, encrypts the first server sensitive data using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext; after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key to obtain the first server sensitive data.
[0008] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the method further includes: in response to the existence of the data key within the validity period in the memory, using the data key to encrypt the second client sensitive data to obtain the second client data ciphertext; sending the second type of request information to the server, the second type of request information including the second client data ciphertext and the first timestamp; wherein, after receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, decrypts the second client data ciphertext using the data key to obtain the second client sensitive data, encrypts the second server sensitive data using the data key to obtain the second server data ciphertext, sends the second type of response information to the client, the second type of response information including the second server data ciphertext; receives the second type of response information, parses the second server data ciphertext according to the second type of response information; decrypts the second server data ciphertext using the data key to obtain the second server sensitive data.
[0009] The present invention also provides another end-to-end encrypted data key distribution method applied to a server, the method comprising: receiving a first type of request information sent by a client; wherein, in response to the absence of a valid data key in a memory, the client randomly generates a session key, encrypts first data using a public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to a current first timestamp, a client identity and a master key, encrypts the data key and the first timestamp using the session key to obtain a data key ciphertext, and sends a first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0010] According to an end-to-end encrypted data key distribution method provided by the present invention, the first data also includes a second timestamp when the first data is encrypted; after decrypting the session key ciphertext using the private key, the method also includes: obtaining the second timestamp based on the session key ciphertext, and verifying the timeliness of the first type of request information based on the second timestamp.
[0011] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the first type of request information also includes a first client data ciphertext, and the first client data ciphertext is obtained by the client using the session key to encrypt the first client sensitive data; after receiving the first type of request information sent by the client, the method also includes: obtaining the first client data ciphertext, decrypting the first client data ciphertext using the session key to obtain the first client sensitive data, encrypting the first server sensitive data using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext; wherein, after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key, and obtains the first server sensitive data.
[0012] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the method further includes: receiving a second type of request information sent by the client, the second type of request information including a second client data ciphertext and the first timestamp; wherein the second client data ciphertext is obtained by the client responding to the existence of the data key in the memory within a validity period and encrypting the second client sensitive data using the data key; parsing the second client data ciphertext and the first timestamp according to the second type of request information, generating the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, decrypting the second client data ciphertext using the data key to obtain the second client sensitive data, encrypting the second server sensitive data using the data key to obtain the second server data ciphertext, and sending a second type of response information to the client, the second type of response information including the second server data ciphertext; wherein the client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, and decrypts the second server data ciphertext using the data key to obtain the second server sensitive data.
[0013] The present invention also provides a client, which includes: a session key generation module, which is used to: randomly generate a session key in response to the absence of a data key within the validity period in the memory; a session key ciphertext acquisition module, which is used to: encrypt first data using the public key of the server to obtain the session key ciphertext; wherein the first data includes the session key; a first type of request information sending module, which is used to: generate a first type of request information and send it to the server, the first type of request information includes the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using the private key, and obtains the session key , according to the current first timestamp, client identity and master key, a data key is generated through a pseudo-random function, the data key and the first timestamp are encrypting by the session key to obtain a data key ciphertext, and a first type of response information is sent to the client, the first type of response information includes the data key ciphertext; a data key ciphertext acquisition module is used to: receive the first type of response information, parse the data key ciphertext according to the first type of response information; a data key acquisition and storage module is used to: decrypt the data key ciphertext using the session key to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory.
[0014] The present invention also provides a server, which includes: a first-class request information receiving module, used to: receive the first-class request information sent by the client; wherein, in response to the absence of a data key within the validity period in the memory, the client randomly generates a session key, encrypts the first data using the public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first-class request information and sends it to the server, the first-class request information includes the session key ciphertext; a data key generation and sending module, used to: parse the first-class request information, obtain the session key ciphertext, and decrypt the session key using a private key ciphertext, obtain the session key, generate a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, use the session key to encrypt the data key and the first timestamp to obtain the data key ciphertext, and send the first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key, obtains the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0015] The present invention also provides an end-to-end encrypted data key distribution system, including the client and server of the above embodiment.
[0016] The present invention also provides 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 end-to-end encrypted data key distribution method as described above is implemented.
[0017] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described end-to-end encrypted data key distribution methods.
[0018] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the end-to-end encrypted data key distribution method as described above is implemented.
[0019] The end-to-end encrypted data key distribution method, electronic device and program product provided by the present invention randomly generate a session key in response to the absence of a valid data key in the memory; encrypt the first data using the public key of the server to obtain the session key ciphertext; wherein the first data includes the session key; generate a first type of request information and send it to the server, the first type of request information includes the session key ciphertext; wherein after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using the private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends the first type of response information to the client, the first type of response information includes the data key ciphertext; receives the first type of response information, and parses the data key ciphertext according to the first type of response information; decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory, thereby greatly improving the security of the end-to-end communication and reducing the calculation and storage burden of the server. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the present invention or 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 This is one of the flow charts of the end-to-end encrypted data key distribution method provided by the present invention.
[0022] Figure 2This is the second flow chart of the end-to-end encrypted data key distribution method provided by the present invention.
[0023] Figure 3 This is the third flow chart of the end-to-end encrypted data key distribution method provided by the present invention.
[0024] Figure 4 It is a structural schematic diagram of the client provided by the present invention.
[0025] Figure 5 It is a structural diagram of the service end provided by the present invention.
[0026] Figure 6 It is a structural diagram of the end-to-end encrypted data key distribution system provided by the present invention.
[0027] Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] Figure 1 It is one of the flow charts of the end-to-end encrypted data key distribution method provided by the present invention, which is applied to the client, such as Figure 1 As shown, the method includes the following: Step S1: In response to the absence of a valid data key in the memory, a session key is randomly generated.
[0030] In the end-to-end encrypted data key distribution method provided by the present invention, the process in which the server and the client generate and store data keys through interaction is called a handshake process.
[0031] The server generates a data key and sends it to the client. The client saves the data key in memory to prevent attackers from reversing the key. Set a validity period for the data key. If the validity period expires, the data key needs to be regenerated. When generating a data key, the client first randomly generates a session key.
[0032] Step S2: Use the public key of the server to encrypt the first data to obtain a session key ciphertext; wherein the first data includes the session key.
[0033] The client pre-stores the public key of the server and uses the public key of the server to encrypt the first data to obtain the session key ciphertext. When the client uses the public key of the server to encrypt the first data to obtain the session key ciphertext, the encryption process can be performed by executing an asymmetric encryption algorithm (such as RSA).
[0034] The first data includes a session key. If the first data only includes the session key, the client encrypts the session key using the public key of the server to obtain a ciphertext of the session key. If the first data also includes other information, the client encrypts the session key and other information using the public key of the server to obtain a ciphertext of the session key.
[0035] Step S3, generate a first type of request information and send it to the server, the first type of request information includes the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, uses the private key to decrypt the session key ciphertext to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, client identity and master key, uses the session key to encrypt the data key and the first timestamp to obtain the data key ciphertext, and sends a first type of response information to the client, the first type of response information includes the data key ciphertext.
[0036] The client generates a first type of request information and sends it to the server. The first type of request information includes a session key ciphertext. The first type of request information is a request information requesting the server to generate a data key. After receiving the first type of request information, the server obtains the session key ciphertext, and uses the private key to decrypt the session key ciphertext according to the asymmetric encryption algorithm used during encryption to obtain the session key. According to the current first timestamp, client identity and master key, a data key is generated through a pseudo-random function. By executing a symmetric encryption algorithm (such as the AES algorithm), the data key and the first timestamp are encrypted using the session key to obtain the data key ciphertext, and the first type of response information is sent to the client. The first type of response information includes the data key ciphertext.
[0037] Step S4: Receive the first type of response information, and parse the data key ciphertext according to the first type of response information.
[0038] The client receives the first type of response information and parses the data key ciphertext according to the first type of response information. If the first type of response information only includes the data key ciphertext, the data key ciphertext can be directly used as the first type of response information, and the data key ciphertext is obtained when the first type of response information is received.
[0039] Step S5: Use the session key to decrypt the data key ciphertext to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory.
[0040] The client can execute a symmetric encryption algorithm (such as AES) and use the session key to decrypt the data key ciphertext to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory. During the validity period of the data key, the data on the client and the server can be encrypted based on the data key.
[0041] The end-to-end encrypted data key distribution method provided by the present invention has the following characteristics: 1. Store the data key in the client memory to prevent attackers from obtaining the key through reverse engineering.
[0042] 2. The session key is randomly generated by the client and passed to the server through the server's public key. The data key for encrypting data is generated from the server's master key and returned to the client through the session key. Finally, the data key is saved by the client. After this session, data is symmetrically encrypted until the data key expires. The benefits are: a) If public key encryption is used for each session, the computing cost of the server will increase. Therefore, this solution uses symmetric keys to encrypt data except for the first session (handshake process); b) If the data key or session key of each client is stored by the server, the storage burden of the server will be greatly increased. Therefore, this solution enables the client to store the data key, and the server uses the master key to generate the data key based on the first timestamp and client identity as input.
[0043] 3. Set an expiration period for the data key. Use the same data key during the expiration period. After the expiration period, delete and regenerate it to prevent replay attacks and avoid the leakage of a large amount of historical or future information after the attacker obtains a certain data key.
[0044] The end-to-end encrypted data key distribution method provided by the present invention randomly generates a session key in response to the absence of a valid data key in the memory; encrypts the first data using the public key of the server to obtain the session key ciphertext; wherein the first data includes the session key; generates a first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using the private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends the first type of response information to the client, the first type of response information includes the data key ciphertext; receives the first type of response information, and parses the data key ciphertext according to the first type of response information; decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory, thereby greatly improving the security of the end-to-end communication and reducing the calculation and storage burden of the server.
[0045] According to an end-to-end encrypted data key distribution method provided by the present invention, the first data also includes a second timestamp when the first data is encrypted; after the server executes the decryption of the session key ciphertext using the private key, it also obtains the second timestamp and verifies the timeliness of the first type of request information based on the second timestamp.
[0046] Replay attacks can be carried out by sending data at another time after intercepting it. To verify the timeliness of the first request information and avoid replay attacks, the first data also includes the second timestamp when the first data is encrypted; the public key of the server can be used to encrypt the session key and the second timestamp to obtain the session key ciphertext. After the server uses the private key to decrypt the session key ciphertext, it obtains the session key and the second timestamp. The server verifies the timeliness of the first type of request information based on the second timestamp.
[0047] The end-to-end encrypted data key distribution method provided by the present invention includes the first data also including the second timestamp when the first data is encrypted. After the server uses the private key to decrypt the session key ciphertext, it also obtains the second timestamp and verifies the timeliness of the first type of request information based on the second timestamp, thereby further improving the security of end-to-end communication.
[0048] According to a method for distributing end-to-end encrypted data keys provided by the present invention, before generating a first type of request information and sending it to the server, the method further includes: using the session key to encrypt the first client sensitive data to obtain the first client data ciphertext, and the first type of request information also includes the first client data ciphertext; wherein, after receiving the first type of request information, the server also obtains the first client data ciphertext, decrypts the first client data ciphertext using the session key to obtain the first client sensitive data, encrypts the first server sensitive data using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext; after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key to obtain the first server sensitive data.
[0049] During the handshake process, the server and the client can interact with each other to generate and store data keys, and can also interact with each other. During the handshake process, the data interacted between the server and the client are respectively called the first server sensitive data and the first client sensitive data.
[0050] Before generating the first type of request information and sending it to the server, the client uses the session key to encrypt the first client sensitive data to obtain the first client data ciphertext. The client can concatenate the session key ciphertext and the first client data ciphertext to obtain the first type of request information and send it to the server.
[0051] After receiving the first type of request information, the server obtains the session key ciphertext and the first client data ciphertext, uses the private key to decrypt the session key ciphertext to obtain the session key, uses the session key to decrypt the first client data ciphertext to obtain the first client sensitive data. According to the current first timestamp, client identity and master key, a data key is generated through a pseudo-random function, the session key is used to encrypt the data key and the first timestamp to obtain the data key ciphertext, the data key is used to encrypt the first server sensitive data to obtain the first server data ciphertext, the data key ciphertext and the first server data ciphertext are concatenated to obtain the first type of response information, and the first type of response information is sent to the client.
[0052] After receiving the first type of response information, the client parses the data key ciphertext and the first server data ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, stores the data key and the first timestamp in the memory, and decrypts the first server data ciphertext using the data key to obtain the first server sensitive data.
[0053] The end-to-end encrypted data key distribution method provided by the present invention encrypts the sensitive data of the first client by using a session key to obtain the first client data ciphertext, and the first type of request information also includes the first client data ciphertext; wherein, after receiving the first type of request information, the server also obtains the first client data ciphertext, decrypts the first client data ciphertext by using the session key to obtain the first client sensitive data, encrypts the first server sensitive data by using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext, and after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key to obtain the first server sensitive data, thereby realizing the secure interaction of data during the handshake process between the server and the client.
[0054] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the method further includes: in response to the existence of the data key within the validity period in the memory, using the data key to encrypt the second client sensitive data to obtain the second client data ciphertext; sending the second type of request information to the server, the second type of request information including the second client data ciphertext and the first timestamp; wherein, after receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, decrypts the second client data ciphertext using the data key to obtain the second client sensitive data, encrypts the second server sensitive data using the data key to obtain the second server data ciphertext, sends the second type of response information to the client, the second type of response information including the second server data ciphertext; receives the second type of response information, parses the second server data ciphertext according to the second type of response information; decrypts the second server data ciphertext using the data key to obtain the second server sensitive data.
[0055] During the validity period of the data key, the server and client can encrypt the sensitive data of the two parties' communication based on the data key and exchange data. During the data transmission process, the sensitive data of the server is called the second server sensitive data, and the sensitive data of the client is called the second client sensitive data.
[0056] When initiating data transmission, the client first verifies the first timestamp of the data key to determine whether the data key is within the validity period. The first timestamp is used to indicate the generation time of the data key. If there is a data key within the validity period in the memory, the data key is used to encrypt the sensitive data of the second client to obtain the second client data ciphertext. The client sends the second type of request information to the server, and the second type of request information includes the second client data ciphertext and the first timestamp. After receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, and generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key. Since the first timestamp, the client identity and the master key are the same as when the data key was generated last time, the generated data key is the same as the last data key. The server uses the data key to decrypt the second client data ciphertext to obtain the second client sensitive data, and uses the data key to encrypt the second server sensitive data to obtain the second server data ciphertext, and sends the second type of response information to the client, and the second type of response information includes the second server data ciphertext. The second server data ciphertext can be directly sent to the client as the second type of response information.
[0057] The client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, decrypts the second server data ciphertext using the data key, and obtains the second server sensitive data.
[0058] The end-to-end encrypted data key distribution method provided by the present invention responds to the existence of a data key within the validity period in the memory, uses the data key to encrypt the sensitive data of the second client to obtain the second client data ciphertext, and sends the second type of request information to the server. The second type of request information includes the second client data ciphertext and the first timestamp. After receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, uses the data key to decrypt the second client data ciphertext to obtain the second client sensitive data, uses the data key to encrypt the second server sensitive data to obtain the second server data ciphertext, sends the second type of response information to the client, the second type of response information includes the second server data ciphertext, receives the second type of response information, parses the second server data ciphertext according to the second type of response information, and uses the data key to decrypt the second server data ciphertext to obtain the second server sensitive data, thereby further improving the security of end-to-end communication.
[0059] Figure 2 This is a second flow chart of the end-to-end encrypted data key distribution method provided by the present invention, which is applied to the server, such as Figure 2 As shown, the method includes: Step 101, receiving a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts first data using a public key of the server to obtain a session key ciphertext, wherein the first data includes the session key, generates the first type of request information and sends it to the server, wherein the first type of request information includes the session key ciphertext.
[0060] In the end-to-end encrypted data key distribution method provided by the present invention, the process in which the server and the client generate and store data keys through interaction can be called a handshake process.
[0061] The server generates a data key and sends it to the client. The client saves the data key in memory to prevent attackers from reversing the key. Set a validity period for the data key. If the validity period expires, the data key needs to be regenerated.
[0062] When generating a data key, the client first randomly generates a session key. The client pre-stores the public key of the server, and uses the public key of the server to encrypt the first data to obtain the session key ciphertext. When the client uses the public key of the server to encrypt the first data to obtain the session key ciphertext, the encryption process can be performed by executing an asymmetric encryption algorithm (such as RSA).
[0063] The first data includes a session key. If the first data only includes the session key, the client encrypts the session key using the public key of the server to obtain a ciphertext of the session key. If the first data also includes other information, the client encrypts the session key and other information using the public key of the server to obtain a ciphertext of the session key.
[0064] The client generates a first type of request information and sends it to the server. The first type of request information includes a session key ciphertext. The first type of request information is request information for requesting the server to generate a data key.
[0065] Step 102: parse the first type of request information, obtain the session key ciphertext, use the private key to decrypt the session key ciphertext to obtain the session key, generate a data key through a pseudo-random function according to the current first timestamp, client identity and master key, use the session key to encrypt the data key and the first timestamp to obtain the data key ciphertext, and send the first type of response information to the client, the first type of response information including the data key ciphertext; wherein the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key, obtains the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0066] After receiving the first type of request information, the server obtains the session key ciphertext, and uses the private key to decrypt the session key ciphertext according to the asymmetric encryption algorithm used during encryption to obtain the session key. According to the current first timestamp, client identity and master key, the server generates a data key through a pseudo-random function, and executes a symmetric encryption algorithm (such as the AES algorithm) to encrypt the data key and the first timestamp using the session key to obtain the data key ciphertext, and sends the first type of response information to the client. The first type of response information includes the data key ciphertext.
[0067] The client receives the first type of response information and parses the data key ciphertext according to the first type of response information. If the first type of response information only includes the data key ciphertext, the data key ciphertext can be directly used as the first type of response information, and the data key ciphertext is obtained when the first type of response information is received.
[0068] The client can execute a symmetric encryption algorithm (such as AES) and use the session key to decrypt the data key ciphertext to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory. During the validity period of the data key, the data on the client and the server can be encrypted based on the data key.
[0069] The end-to-end encrypted data key distribution method provided by the present invention receives a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts the first data using the public key of the server to obtain the session key ciphertext, the first data includes the session key, generates a first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, uses the private key to decrypt the session key ciphertext to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, and sends the first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key, obtains the data key and the first timestamp, and stores the data key and the first timestamp in the memory, thereby greatly improving the security of end-to-end communication and reducing the computing and storage burden of the server.
[0070] According to an end-to-end encrypted data key distribution method provided by the present invention, the first data also includes a second timestamp when the first data is encrypted; after decrypting the session key ciphertext using the private key, the method also includes: obtaining the second timestamp based on the session key ciphertext, and verifying the timeliness of the first type of request information based on the second timestamp.
[0071] Replay attacks can be carried out by sending data at another time after intercepting it. To verify the timeliness of the first request information and avoid replay attacks, the first data also includes the second timestamp when the first data is encrypted; the public key of the server can be used to encrypt the session key and the second timestamp to obtain the session key ciphertext. After the server uses the private key to decrypt the session key ciphertext, it obtains the session key and the second timestamp. The server verifies the timeliness of the first type of request information based on the second timestamp.
[0072] The end-to-end encrypted data key distribution method provided by the present invention further improves the security of end-to-end communication by including the first data also in the second timestamp when the first data is encrypted. After decrypting the session key ciphertext with the private key, the second timestamp is obtained according to the session key ciphertext, and the timeliness of the first type of request information is verified according to the second timestamp.
[0073] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the first type of request information also includes a first client data ciphertext, and the first client data ciphertext is obtained by the client using the session key to encrypt the first client sensitive data; after receiving the first type of request information sent by the client, the method also includes: obtaining the first client data ciphertext, decrypting the first client data ciphertext using the session key to obtain the first client sensitive data, encrypting the first server sensitive data using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext; wherein, after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key, and obtains the first server sensitive data.
[0074] During the handshake process, the server and the client can interact with each other to generate and store data keys, and can also interact with each other. During the handshake process, the data interacted between the server and the client are respectively called the first server sensitive data and the first client sensitive data.
[0075] Before generating the first type of request information and sending it to the server, the client uses the session key to encrypt the first client sensitive data to obtain the first client data ciphertext. The client can concatenate the session key ciphertext and the first client data ciphertext to obtain the first type of request information and send it to the server.
[0076] After receiving the first type of request information, the server obtains the session key ciphertext and the first client data ciphertext, uses the private key to decrypt the session key ciphertext to obtain the session key, uses the session key to decrypt the first client data ciphertext to obtain the first client sensitive data. According to the current first timestamp, client identity and master key, a data key is generated through a pseudo-random function, the session key is used to encrypt the data key and the first timestamp to obtain the data key ciphertext, the data key is used to encrypt the first server sensitive data to obtain the first server data ciphertext, the data key ciphertext and the first server data ciphertext are concatenated to obtain the first type of response information, and the first type of response information is sent to the client.
[0077] After receiving the first type of response information, the client parses the data key ciphertext and the first server data ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, stores the data key and the first timestamp in the memory, and decrypts the first server data ciphertext using the data key to obtain the first server sensitive data.
[0078] The end-to-end encrypted data key distribution method provided by the present invention also includes a first client data ciphertext through the first type of request information, and the first client data ciphertext is obtained by the client using a session key to encrypt the first client sensitive data. After receiving the first type of request information sent by the client, the first client data ciphertext is obtained, the first client data ciphertext is decrypted using the session key to obtain the first client sensitive data, and the first server sensitive data is encrypted using the data key to obtain the first server data ciphertext. The first type of response information also includes the first server data ciphertext. After receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key to obtain the first server sensitive data, thereby realizing secure interaction of data during the handshake process between the server and the client.
[0079] According to a method for distributing end-to-end encrypted data keys provided by the present invention, the method further includes: receiving a second type of request information sent by the client, the second type of request information including a second client data ciphertext and the first timestamp; wherein the second client data ciphertext is obtained by the client responding to the existence of the data key in the memory within a validity period and encrypting the second client sensitive data using the data key; parsing the second client data ciphertext and the first timestamp according to the second type of request information, generating the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, decrypting the second client data ciphertext using the data key to obtain the second client sensitive data, encrypting the second server sensitive data using the data key to obtain the second server data ciphertext, and sending a second type of response information to the client, the second type of response information including the second server data ciphertext; wherein the client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, and decrypts the second server data ciphertext using the data key to obtain the second server sensitive data.
[0080] During the validity period of the data key, the server and client can encrypt the sensitive data of the two parties' communication based on the data key and exchange data. During the data transmission process, the sensitive data of the server is called the second server sensitive data, and the sensitive data of the client is called the second client sensitive data.
[0081] When initiating data transmission, the client first verifies the first timestamp of the data key to determine whether the data key is within the validity period. The first timestamp is used to indicate the generation time of the data key. If there is a data key within the validity period in the memory, the data key is used to encrypt the sensitive data of the second client to obtain the second client data ciphertext. The client sends the second type of request information to the server, and the second type of request information includes the second client data ciphertext and the first timestamp. After receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, and generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key. Since the first timestamp, the client identity and the master key are the same as when the data key was generated last time, the generated data key is the same as the last data key. The server uses the data key to decrypt the second client data ciphertext to obtain the second client sensitive data, and uses the data key to encrypt the second server sensitive data to obtain the second server data ciphertext, and sends the second type of response information to the client, and the second type of response information includes the second server data ciphertext. The second server data ciphertext can be directly sent to the client as the second type of response information.
[0082] The client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, decrypts the second server data ciphertext using the data key, and obtains the second server sensitive data.
[0083] The end-to-end encrypted data key distribution method provided by the present invention receives the second type of request information sent by the client, the second type of request information includes the second client data ciphertext and the first timestamp, the second client data ciphertext is obtained by the client responding to the existence of a data key in the memory within a validity period, and using the data key to encrypt the second client sensitive data, parse the second client data ciphertext and the first timestamp according to the second type of request information, generate the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, use the data key to decrypt the second client data ciphertext to obtain the second client sensitive data, use the data key to encrypt the second server sensitive data to obtain the second server data ciphertext, send the second type of response information to the client, the second type of response information includes the second server data ciphertext, the client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, and uses the data key to decrypt the second server data ciphertext to obtain the second server sensitive data, thereby further improving the security of end-to-end communication.
[0084] Figure 3 This is the third flow chart of the end-to-end encrypted data key distribution method provided by the present invention. Figure 3 An embodiment of the end-to-end encrypted data key distribution method provided by the present invention is given through the interaction between a server (Server) and a client (Client).
[0085] Client input: Server's long-term RSA public key pubkey.
[0086] Server input: Server's long-term RSA public and private key pair (privkey, pubkey), master key mk.
[0087] 1. In the Handshake phase, the Client transmits the session key to the Server through an encrypted channel, and the Server returns the data key to the Client. Client: Randomly generate a session key sk; Use the server's public key to perform RSA on the session key and the corresponding timestamp (ts_sk) to obtain the session key ciphertext, cipher_sk := RSA(pubkey; sk||ts_sk); Use the session key to perform AES encryption on the client sensitive data (c_data) to obtain the data ciphertext, cipher_c_data := AES(sk; c_data); Concatenate the session key ciphertext and data ciphertext as the first type of request information (req_v1) and send it to the Server; Server: After receiving the first type of request information, parse it into session key ciphertext and data ciphertext; Decrypt the session key ciphertext using the long-term private key to obtain the session key and timestamp, sk||ts_sk := RSA(privkey; cipher_sk); Verify the validity of the timestamp; Use the session key to decrypt the client's data ciphertext to obtain the client's sensitive data, c_data := AES(sk;cipher_c_data); Take the current timestamp (ts_dk) and the client identity (id_c) as input, and generate the data key corresponding to the master key through a pseudo-random function, dk := PRF(mk; ts_dk||id_c); Use the session key to perform AES encryption on the data key and the timestamp when the data key was generated (ts_dk) to obtain the data key ciphertext, cipher_dk := AES(sk; dk||ts_dk); Use the data key to perform AES encryption on the server sensitive data (s_data) to obtain the data ciphertext, cipher_s_data := AES(dk; s_data); The data key ciphertext and data ciphertext are concatenated and sent to the Client as the first type of response information (resp_v1); Client: After receiving the first type of response information, parse it into data key ciphertext and data ciphertext; Use the session key to decrypt the data key ciphertext to obtain the data key and the timestamp when the data key was generated, dk||ts_dk := AES(sk; cipher_dk); Use the data key to decrypt the data ciphertext and obtain the server sensitive data, s_data := AES(dk; cipher_s_data); Stores the data key and the corresponding timestamp.
[0088] Transport (data transmission) phase: The client uses the valid data key to encrypt sensitive data and decrypt the returned response ciphertext; Client: Verify the timestamp of the data key. If it is invalid, execute the Handshake phase. If valid, use the data key to perform AES encryption on the sensitive data to obtain the data ciphertext, cipher_c_data := AES(dk; c_data); Send the data ciphertext and the timestamp when the data key was generated (ts_dk) to the server as the second type of request information (req_v2); Server: After receiving the second type of request information, parse it into data ciphertext and timestamp (ts_dk); Using the timestamp (ts_dk) and the client identity as input, a pseudo-random function is used to generate the data key corresponding to the master key, dk := PRF(mk; ts_dk||id_c); Use the data key to decrypt the data ciphertext and obtain the client sensitive data, c_data := AES(dk; cipher_c_data); Use the data key to perform AES encryption on the server sensitive data to obtain the data ciphertext, cipher_s_data :=AES(dk; s_data); Send the encrypted data to the Client as the second type of response information (req_v2); Client: After receiving the second type of response information, parse it into data ciphertext; Use the data key to decrypt the data ciphertext and obtain the server sensitive data, s_data := AES(dk; cipher_s_data).
[0089] Among them, in the Handshake stage, the client randomly generates a session key and passes it to the server using the server's public key. The role of the session key is to encrypt the client data in this stage, but it cannot encrypt future communication data. Otherwise, the server needs to store the session key, which will increase the storage cost of the server. If a public key is used to encrypt a session key to the server each time, the computing cost will increase; therefore, the server needs to return a generated data key and return it to the client via the session key.
[0090] In the Transport phase, it is necessary to verify whether the current data key has expired. If it has expired, the client needs to re-execute the Handshake phase; each time the server receives the ciphertext in the Transport phase, it needs to regenerate the data key based on the timestamp and client identity.
[0091] Since only Handshake involves one public key decryption, the others are symmetric encryption and decryption, which greatly reduces the computing burden on the server while improving the security of end-to-end communications.
[0092] The client provided by the present invention is described below. The client described below and the end-to-end encrypted data key distribution method applied to the client described above can be referenced to each other.
[0093] Figure 4 Schematic diagram of the structure of the client provided by the present invention. Figure 4 As shown, the client 1 includes a session key generation module 10, a session key ciphertext acquisition module 20, a first-class request information sending module 30, a data key ciphertext acquisition module 40 and a data key acquisition and storage module 50, wherein: the session key generation module 10 is used to: in response to the absence of a data key within the validity period in the memory, randomly generate a session key; the session key ciphertext acquisition module 20 is used to: encrypt first data using the public key of the server to obtain a session key ciphertext; wherein the first data includes the session key; the first-class request information sending module 30 is used to: generate a first-class request information and send it to the server, the first-class request information includes the session key ciphertext; wherein, after receiving the first-class request information, the server obtains the Session key ciphertext, use the private key to decrypt the session key ciphertext to obtain the session key, generate a data key through a pseudo-random function according to the current first timestamp, client identity and master key, use the session key to encrypt the data key and the first timestamp to obtain the data key ciphertext, send the first type of response information to the client, the first type of response information includes the data key ciphertext; the data key ciphertext acquisition module 40 is used to: receive the first type of response information, parse the data key ciphertext according to the first type of response information; the data key acquisition and storage module 50 is used to: use the session key to decrypt the data key ciphertext to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory.
[0094] The client provided by the present invention randomly generates a session key in response to the absence of a data key within the validity period in the memory; encrypts the first data with the public key of the server to obtain the session key ciphertext; wherein the first data includes the session key; generates a first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext with the private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp with the session key to obtain the data key ciphertext, sends the first type of response information to the client, the first type of response information includes the data key ciphertext; receives the first type of response information, and parses the data key ciphertext according to the first type of response information; decrypts the data key ciphertext with the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory, thereby greatly improving the security of end-to-end communication and reducing the computing and storage burden of the server.
[0095] Figure 5 It is a schematic diagram of the structure of the server provided by the present invention. Figure 5 As shown, the server 2 includes a first-class request information receiving module 100 and a data key generating and sending module 200, wherein: the first-class request information receiving module 100 is used to: receive the first-class request information sent by the client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, uses the public key of the server to encrypt the first data, obtains the session key ciphertext, the first data includes the session key, generates the first-class request information and sends it to the server, the first-class request information includes the session key ciphertext; the data key generating and sending module 200 is used to: parse the first-class request information, obtain the session key ciphertext The session key ciphertext is decrypted using the private key to obtain the session key, a data key is generated through a pseudo-random function according to the current first timestamp, the client identity and the master key, the data key and the first timestamp are encrypted using the session key to obtain the data key ciphertext, and a first type of response information is sent to the client, the first type of response information including the data key ciphertext; wherein the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0096] The server provided by the present invention receives a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts the first data with the public key of the server to obtain the session key ciphertext, the first data includes the session key, generates a first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, uses the private key to decrypt the session key ciphertext to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp with the session key to obtain the data key ciphertext, and sends the first type of response information to the client, the first type of response information includes the data key ciphertext; wherein the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext with the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory, thereby greatly improving the security of end-to-end communication and reducing the computing and storage burden of the server.
[0097] Figure 6 Schematic diagram of the structure of the end-to-end encrypted data key distribution system provided by the present invention. Figure 6 As shown, the system includes a client 1 and a server 2. The client 1 may be the client in the above embodiment, and the server 2 may be the server in the above embodiment.
[0098] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7As shown, the electronic device may include: a processor (processor) 710 , a communication interface (Communications Interface) 720 , a memory (memory) 730 and a communication bus 740 , wherein the processor 710 , the communication interface 720 , and the memory 730 communicate with each other through the communication bus 740 . The processor 710 may call the logic instructions in the memory 730 to execute the end-to-end encrypted data key distribution method, the method comprising: in response to the absence of a valid data key in the memory, randomly generating a session key; encrypting the first data using the public key of the server to obtain the session key ciphertext; wherein the first data includes the session key; generating a first type of request information and sending it to the server, the first type of request information including the session key ciphertext; wherein after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using the private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends the first type of response information to the client, the first type of response information including the data key ciphertext; receives the first type of response information, and parses the data key ciphertext according to the first type of response information; decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory; Or the method includes: receiving a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts the first data using the public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends a first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0099] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention 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 method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0100] On the other hand, the present invention further provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the end-to-end encrypted data key distribution method provided by the above methods, the method including: in response to the absence of a valid data key in the memory, randomly generating a session key; using the public key of the server to encrypt first data to obtain a session key ciphertext; wherein the first data includes the session key; generating a first type of request information and sending it to the server, the first type of request information including the session key ciphertext; wherein the server, upon receiving the first After receiving the first type of request information, the session key ciphertext is obtained, the session key ciphertext is decrypted by using the private key to obtain the session key, a data key is generated by a pseudo-random function according to the current first timestamp, the client identity and the master key, the data key and the first timestamp are encrypted by using the session key to obtain the data key ciphertext, and a first type of response information is sent to the client, where the first type of response information includes the data key ciphertext; the first type of response information is received, and the data key ciphertext is parsed according to the first type of response information; the data key ciphertext is decrypted by using the session key to obtain the data key and the first timestamp, and the data key and the first timestamp are stored in the memory; Or the method includes: receiving a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts the first data using the public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends a first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0101] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the end-to-end encrypted data key distribution method provided by the above methods, the method comprising: in response to the absence of a valid data key in the memory, randomly generating a session key; encrypting first data using a public key of the server to obtain a session key ciphertext; wherein the first data includes the session key; generating a first type of request information and sending it to the server, the first type of request information including the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, decrypt the session key ciphertext with a private key to obtain the session key, generate a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypt the data key and the first timestamp with the session key to obtain the data key ciphertext, send the first type of response information to the client, the first type of response information includes the data key ciphertext; receive the first type of response information, parse the data key ciphertext according to the first type of response information; decrypt the data key ciphertext with the session key to obtain the data key and the first timestamp, and store the data key and the first timestamp in the memory; Or the method includes: receiving a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts the first data using the public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; parses the first type of request information, obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, sends a first type of response information to the client, the first type of response information includes the data key ciphertext; wherein, the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key to obtain the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
[0102] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0103] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for distributing data keys for end-to-end encryption, the method being applied to a client, characterized in that: include: In response to the absence of a valid data key in the memory, randomly generating a session key; Encrypting the first data using the public key of the server to obtain a session key ciphertext; wherein the first data includes the session key; Generate a first type of request information and send it to the server, the first type of request information includes the session key ciphertext; wherein, after receiving the first type of request information, the server obtains the session key ciphertext, decrypts the session key ciphertext using a private key to obtain the session key, generates a data key through a pseudo-random function according to the current first timestamp, the client identity and the master key, encrypts the data key and the first timestamp using the session key to obtain the data key ciphertext, and sends a first type of response information to the client, the first type of response information includes the data key ciphertext; receiving the first type of response information, and parsing the data key ciphertext according to the first type of response information; The data key ciphertext is decrypted using the session key to obtain the data key and the first timestamp, and the data key and the first timestamp are stored in the memory.
2. The method for distributing data keys for end-to-end encryption according to claim 1, characterized in that: The first data also includes a second timestamp when the first data is encrypted; after the server executes the decryption of the session key ciphertext using the private key, it also obtains the second timestamp and verifies the timeliness of the first type of request information based on the second timestamp.
3. The method for distributing data keys for end-to-end encryption according to claim 1, characterized in that: Before generating the first type of request information and sending it to the server, the method further includes: The first client sensitive data is encrypted using the session key to obtain the first client data ciphertext, and the first type of request information also includes the first client data ciphertext; wherein, after receiving the first type of request information, the server also obtains the first client data ciphertext, decrypts the first client data ciphertext using the session key to obtain the first client sensitive data, and encrypts the first server sensitive data using the data key to obtain the first server data ciphertext, and the first type of response information also includes the first server data ciphertext; After receiving the first type of response information, the client further parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key, and obtains the first server sensitive data.
4. The method for distributing data keys for end-to-end encryption according to claim 1, characterized in that: The method further comprises: In response to the data key existing in the memory within the validity period, the second client sensitive data is encrypted using the data key to obtain the second client data ciphertext; Sending a second type of request information to the server, the second type of request information including the second client data ciphertext and the first timestamp; wherein, after receiving the second type of request information, the server parses the second client data ciphertext and the first timestamp, generates the data key through a pseudo-random function according to the first timestamp, the client identity and the master key, decrypts the second client data ciphertext using the data key to obtain the second client sensitive data, encrypts the second server sensitive data using the data key to obtain the second server data ciphertext, and sends a second type of response information to the client, the second type of response information including the second server data ciphertext; receiving the second type of response information, and parsing the second server data ciphertext according to the second type of response information; The data key is used to decrypt the second server data ciphertext to obtain the second server sensitive data.
5. A method for distributing data keys for end-to-end encryption, the method being applied to a server, characterized in that: include: Receive a first type of request information sent by a client; wherein, in response to the absence of a valid data key in the memory, the client randomly generates a session key, encrypts first data using a public key of the server to obtain a session key ciphertext, the first data includes the session key, generates the first type of request information and sends it to the server, the first type of request information includes the session key ciphertext; Parse the first type of request information, obtain the session key ciphertext, use the private key to decrypt the session key ciphertext to obtain the session key, generate a data key through a pseudo-random function according to the current first timestamp, client identity and master key, use the session key to encrypt the data key and the first timestamp to obtain the data key ciphertext, send the first type of response information to the client, the first type of response information includes the data key ciphertext; wherein the client receives the first type of response information, parses the data key ciphertext according to the first type of response information, decrypts the data key ciphertext using the session key, obtains the data key and the first timestamp, and stores the data key and the first timestamp in the memory.
6. The method for distributing data keys for end-to-end encryption according to claim 5, characterized in that: The first data further includes a second timestamp when the first data is encrypted; After decrypting the session key ciphertext using the private key, the method further includes: The second timestamp is obtained according to the session key ciphertext, and the timeliness of the first type of request information is verified according to the second timestamp.
7. The method for distributing data keys for end-to-end encryption according to claim 5, characterized in that: The first type of request information also includes first client data ciphertext, where the first client data ciphertext is obtained by the client encrypting the first client sensitive data using the session key; After receiving the first type of request information sent by the client, the method further includes: Obtain the first client data ciphertext, use the session key to decrypt the first client data ciphertext to obtain the first client sensitive data, use the data key to encrypt the first server sensitive data to obtain the first server data ciphertext, the first type of response information also includes the first server data ciphertext; wherein, after receiving the first type of response information, the client also parses the first server data ciphertext according to the first type of response information, decrypts the first server data ciphertext according to the data key, and obtains the first server sensitive data.
8. The method for distributing data keys for end-to-end encryption according to claim 5, characterized in that: The method further comprises: Receiving second-type request information sent by the client, the second-type request information including second-client data ciphertext and the first timestamp; wherein the second-client data ciphertext is obtained by the client responding to the data key within the validity period in the memory by encrypting the second-client sensitive data using the data key; The second client data ciphertext and the first timestamp are parsed out according to the second type of request information; the data key is generated through a pseudo-random function according to the first timestamp, the client identity and the master key; the second client data ciphertext is decrypted using the data key to obtain the second client sensitive data; the second server sensitive data is encrypted using the data key to obtain the second server data ciphertext; the second type of response information is sent to the client, and the second type of response information includes the second server data ciphertext; wherein the client receives the second type of response information, parses the second server data ciphertext according to the second type of response information, and decrypts the second server data ciphertext using the data key to obtain the second server sensitive data.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the end-to-end encrypted data key distribution method as described in any one of claims 1 to 8 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the end-to-end encrypted data key distribution method as described in any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Method and computer for cryptographic protection of control communication in it system and / or service access to it system
CN120358087A