Communication method and device
By generating public keys and private keys at the communication end, and using elliptic curve cryptography and Diffie-Hellman key exchange algorithm to generate session keys, the problem of data communication security threats in the existing technology is solved, and safe and reliable data is achieved. transmission.
Patent Information
- Application Number
- CN202411070138.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-10-15
AI Technical Summary
Existing data communication has security threats in encrypted transmission and is prone to eavesdropping, tampering and forgery, and lacks safe and reliable communication solutions.
By generating public keys and private keys at the communication end, using elliptic curve cryptography algorithm and Diffie-Hellman key exchange algorithm to generate session keys, and performing key matching confirmation to ensure the encryption and decryption of communication content.
Safe and reliable data communication is achieved, ensuring that the communication content is not tampered with during transmission, and enhancing the security and reliability of the communication process.
Smart Images

Figure CN118784236A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a communication method and device. Background Art
[0002] Existing web applications face multiple security threats during data transmission. Although protocols such as HTTPS (Hypertext Transfer Protocol Secure) provide basic protection in encrypted data transmission, there are still certain limitations and potential loopholes, which make the transmission vulnerable to eavesdropping, tampering and forgery. Existing technologies do not yet provide a secure and reliable data communication solution. Summary of the invention
[0003] In view of this, an embodiment of the present invention provides a communication method and device, which can realize secure and reliable data communication.
[0004] In a first aspect, an embodiment of the present invention provides a communication method, applied to a first communication terminal, including:
[0005] Generate a first public key and a first private key using a first algorithm, and send the first public key to the second communication end;
[0006] Receiving a second public key sent by the second communication end;
[0007] Generate a first session key using a second algorithm corresponding to the first algorithm and based on the first private key and the second public key;
[0008] Determine whether the first session key matches a second session key; wherein the second session key is generated by the second communication end using the second algorithm according to the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm;
[0009] In response to the first session key matching the second session key, communicating with the second communication end using the first session key.
[0010] Optionally, determining whether the first session key matches the second session key includes:
[0011] Negotiating with the second communication end to determine preset data;
[0012] receiving first confirmation data sent by the second communication end; wherein the first confirmation data is obtained by the second communication end encrypting the preset data using the second session key;
[0013] Using the first session key, decrypting the first confirmation data to obtain first decrypted data;
[0014] In response to the first decrypted data matching the preset data, it is determined that the first session key matches the second session key, and notification information indicating the key matching is sent to the second communication terminal.
[0015] Optionally, determining whether the first session key matches the second session key includes:
[0016] Negotiating with the second communication end to determine preset data;
[0017] Using the first session key, encrypting the preset data to obtain second confirmation data;
[0018] sending the second confirmation data to the second communication end, so that the second communication end determines whether the first session key matches the second session key according to the second confirmation data;
[0019] In response to receiving the notification information indicating key matching sent by the second communication end, it is determined that the first session key matches the second session key.
[0020] Optionally, the communicating with the second communication end by using the first session key includes:
[0021] determining first communication content;
[0022] Using the first session key, encrypting the first communication content to obtain first encrypted content;
[0023] The first encrypted content is sent to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
[0024] Optionally, the communicating with the second communication end by using the first session key includes:
[0025] receiving second encrypted content sent by the second communication end; wherein the second encrypted content is encrypted by the second communication end using the second session key;
[0026] Using the first session key, encrypting the second encrypted content to obtain second communication content;
[0027] Perform information processing on the second communication content.
[0028] Optionally, it also includes:
[0029] Determining whether the first communication end and / or the second communication end meets a key refresh condition;
[0030] In response to the first communication terminal and / or the second communication terminal meeting the key refresh condition, the step of using the first algorithm to generate a first public key and a first private key, and sending the first public key to the second communication terminal is re-executed.
[0031] Optionally, the first algorithm is an elliptic curve cryptography algorithm, and the second algorithm is an elliptic curve Diffie-Hellman key exchange algorithm.
[0032] In a second aspect, an embodiment of the present invention provides a communication device, applied to a first communication end, including:
[0033] A public key sending module, used to generate a first public key and a first private key by using a first algorithm, and send the first public key to the second communication end;
[0034] A public key receiving module, used to receive a second public key sent by the second communication end;
[0035] a key generation module, configured to generate a first session key according to the first private key and the second public key by using a second algorithm corresponding to the first algorithm;
[0036] a matching module, configured to determine whether the first session key matches a second session key; wherein the second session key is generated by the second communication terminal using the second algorithm, according to a second private key and the first public key; and the second private key and the second public key are generated by the second communication terminal using the first algorithm;
[0037] The communication module is used for communicating with the second communication end by using the first session key in response to the first session key matching the second session key.
[0038] Optionally, the matching module is specifically used for:
[0039] Negotiating with the second communication end to determine preset data;
[0040] receiving first confirmation data sent by the second communication end; wherein the first confirmation data is obtained by the second communication end encrypting the preset data using the second session key;
[0041] Using the first session key, decrypting the first confirmation data to obtain first decrypted data;
[0042] In response to the first decrypted data matching the preset data, it is determined that the first session key matches the second session key, and notification information indicating the key matching is sent to the second communication terminal.
[0043] Optionally, the matching module is specifically used for:
[0044] Negotiating with the second communication end to determine preset data;
[0045] Using the first session key, encrypting the preset data to obtain second confirmation data;
[0046] sending the second confirmation data to the second communication end, so that the second communication end determines whether the first session key matches the second session key according to the second confirmation data;
[0047] In response to receiving the notification information indicating key matching sent by the second communication end, it is determined that the first session key matches the second session key.
[0048] Optionally, the communication module is specifically used for:
[0049] determining first communication content;
[0050] Using the first session key, encrypting the first communication content to obtain first encrypted content;
[0051] The first encrypted content is sent to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
[0052] Optionally, the communication module is specifically used for:
[0053] receiving second encrypted content sent by the second communication end; wherein the second encrypted content is encrypted by the second communication end using the second session key;
[0054] Using the first session key, encrypting the second encrypted content to obtain second communication content;
[0055] Perform information processing on the second communication content.
[0056] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments.
[0057] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method described in any of the above embodiments.
[0058] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, which implements the method described in any of the above embodiments when executed by a processor.
[0059] An embodiment of the above invention has the following advantages or beneficial effects: the first communication end and the second communication end respectively use the first algorithm to generate their own public key and private key, and send their respective public keys to the other communication end. The first communication end uses the second algorithm to generate a first session key based on its own private key and the public key of the other end. The second communication end uses the second algorithm to generate a second session key based on its own private key and the public key of the other end. The cryptographic properties of the first algorithm and the second algorithm ensure that the first communication end and the second communication end can obtain matching session keys. When the first communication end and the second communication end determine that the first session key matches the second session key, they use their respective session keys to communicate, ensuring that the communication content can be effectively encrypted and decrypted. Therefore, the scheme of the embodiment of the present invention can achieve secure and reliable data communication.
[0060] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0062] Figure 1 It is a flowchart of a communication method provided by the first embodiment of the present invention.
[0063] Figure 2 It is a flow chart of a communication method provided by the second embodiment of the present invention.
[0064] Figure 3 It is a flowchart of a communication method provided by the third embodiment of the present invention.
[0065] Figure 4 It is a structural schematic diagram of a communication device provided by an embodiment of the present invention.
[0066] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0067] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0068] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0069] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0070] Figure 1 is a flow chart of a communication method provided by the first embodiment of the present invention, which is applied to a first communication terminal, such as Figure 1 As shown, the method includes:
[0071] Step 101: Generate a first public key and a first private key using a first algorithm, and send the first public key to a second communication end.
[0072] The method of the embodiment of the present invention is applied to the communication between the first communication terminal and the second communication terminal. The first communication terminal may be a server or a terminal. The second communication terminal may be a server or a terminal. The method of the embodiment of the present invention may be applied to the communication between two servers, the communication between two terminals, the communication between a server and a terminal, etc.
[0073] Step 102: Receive a second public key sent by the second communication end.
[0074] The second communication end generates a second public key and a second private key using the first algorithm, and sends the second public key to the first communication end.
[0075] Step 103: Generate a first session key according to the first private key and the second public key using a second algorithm corresponding to the first algorithm.
[0076] The first communication end generates a first session key based on the first private key and the second public key using a second algorithm corresponding to the first algorithm. The second communication end generates a second session key based on the second private key and the first public key using the same second algorithm. The cryptographic properties of the first algorithm and the second algorithm can ensure that the first session key matches the second session key.
[0077] In one embodiment of the present invention, the first algorithm is an ECC (Elliptic Curve Cryptography) algorithm, and the second algorithm is an ECDH (Elliptic Curve Diffie-Hellman) algorithm. The high efficiency of the ECC algorithm is used to reduce the key size, and correspondingly reduce the computing and storage requirements, while still maintaining a high level of security.
[0078] Step 104: Determine whether the first session key matches the second session key; wherein the second session key is generated by the second communication using the second algorithm based on the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm.
[0079] In the case where the communication content between the first communication terminal and the second communication terminal has not been tampered with, the cryptographic characteristics of the first algorithm and the second algorithm can ensure that the first session key matches the second session key. If the communication content between the first communication terminal and the second communication terminal has been tampered with, the first session key does not match the second session key. By determining whether the first session key matches the second session key, the security of the communication is further ensured, and the information exchanged between the two parties can be successfully encrypted and decrypted.
[0080] Step 105: In response to the first session key matching the second session key, communicate with the second communication end using the first session key.
[0081] If the first session key matches the second session key, the first session key is used to communicate with the second communication end. If the first session key does not match the second session key, a prompt message indicating that the keys do not match can be sent to the first communication end and the second communication end respectively, and a new session key can be re-determined, that is, steps 101 to 105 are re-executed.
[0082] In the scheme of the embodiment of the present invention, the first communication end and the second communication end respectively use the first algorithm to generate their own public key and private key, and send their respective public keys to the other communication end. The first communication end uses the second algorithm to generate a first session key based on its own private key and the public key of the other end. The second communication end uses the second algorithm to generate a second session key based on its own private key and the public key of the other end. The cryptographic properties of the first algorithm and the second algorithm ensure that the first communication end and the second communication end can obtain matching session keys. When the first communication end and the second communication end determine that the first session key matches the second session key, they use their respective session keys to communicate, ensuring that the communication content can be effectively encrypted and decrypted. Therefore, the scheme of the embodiment of the present invention can achieve secure and reliable data communication.
[0083] In one embodiment of the present invention, determining whether a first session key matches a second session key includes: negotiating with a second communication terminal to determine preset data; receiving first confirmation data sent by the second communication terminal; wherein the first confirmation data is obtained by the second communication terminal encrypting the preset data using the second session key; using the first session key, decrypting the first confirmation data to obtain first decrypted data; in response to the first decrypted data matching the preset data, determining that the first session key matches the second session key, and sending notification information indicating the key match to the second communication terminal.
[0084] The first communication end negotiates with the second communication end to determine the preset data. The second communication end uses the second session key to encrypt the preset data to obtain first confirmation data, and sends the first confirmation data to the first communication end. The first communication end uses the first session key to decrypt the first confirmation data to obtain first decrypted data. If the first decrypted data matches the preset data, it is determined that the first session key matches the second session key, and the two communication ends can perform subsequent communication.
[0085] In one embodiment of the present invention, determining whether a first session key matches a second session key includes: negotiating with a second communication terminal to determine preset data; encrypting the preset data using the first session key to obtain second confirmation data; sending the second confirmation data to the second communication terminal so that the second communication terminal determines whether the first session key matches the second session key based on the second confirmation data; and determining that the first session key matches the second session key in response to receiving notification information indicating a key match sent by the second communication terminal.
[0086] The first communication end negotiates with the second communication end to determine the preset data. The first communication end uses the first session key to encrypt the preset data to obtain second confirmation data, and sends the second confirmation data to the second communication end. The second communication end uses the second session key to decrypt the second confirmation data to obtain second decrypted data. If the second decrypted data matches the preset data, it is determined that the first session key matches the second session key, and the two communication ends can perform subsequent communication.
[0087] In one embodiment of the present invention, it also includes: determining whether the first communication terminal and / or the second communication terminal meets the key refresh condition; in response to the first communication terminal and / or the second communication terminal meeting the key refresh condition, re-executing the step of using the first algorithm to generate a first public key and a first private key, and sending the first public key to the second communication terminal.
[0088] The key refresh conditions can be set as needed. For example, the communication duration between the first communication end and the second communication end based on the current key is longer than the preset duration, the number of sessions between the first communication end and the second communication end based on the current key is greater than the preset number, etc. By dynamically updating the session key, the security of the communication process is enhanced. If the session key is leaked, it will only affect a limited number of communication sessions and will not threaten other communication sessions.
[0089] Figure 2 is a flow chart of a communication method provided by the second embodiment of the present invention, such as Figure 2 As shown, the method includes:
[0090] Step 201: The first communication end generates a first public key and a first private key using a first algorithm, and sends the first public key to the second communication end.
[0091] Step 202: The first communication end receives the second public key sent by the second communication end.
[0092] Step 203: The first communication end generates a first session key according to the first private key and the second public key using a second algorithm corresponding to the first algorithm.
[0093] Steps 201 to 203 are a process of generating a session key by a first communication end, which may be a server or a terminal.
[0094] Step 204: The second communication end generates a second public key and a second private key using the first algorithm, and sends the second public key to the first communication end.
[0095] Step 205: The second communication end receives the first public key sent by the first communication end.
[0096] Step 206: The second communication end generates a second session key according to the second private key and the first public key using a second algorithm corresponding to the first algorithm.
[0097] Steps 204 to 206 are the process of generating a session key for the second communication end, which may be a server or a terminal.
[0098] Step 207: In response to the first session key matching the second session key, the first communication end communicates with the second communication end using the first session key.
[0099] In the solution of the embodiment of the present invention, the first communication end and the second communication end generate their own public key and private key respectively, and exchange their public keys with the other communication end. The first communication end and the second communication end generate their own session keys based on their own private keys and the other party's public key respectively, and use their own session keys to complete communication when the session keys of the two communication ends match, which can better improve the reliability of communication between the two communication ends.
[0100] Figure 3 is a flow chart of a communication method provided by a third embodiment of the present invention, which is applied to a first communication terminal, such as Figure 3 As shown, the method includes:
[0101] Step 301: Generate a first public key and a first private key using a first algorithm, and send the first public key to a second communication terminal.
[0102] Step 302: Receive a second public key sent by the second communication end.
[0103] Step 303: Generate a first session key according to the first private key and the second public key using a second algorithm corresponding to the first algorithm.
[0104] Step 304: Determine whether the first session key matches the second session key; wherein the second session key is generated by the second communication using the second algorithm based on the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm.
[0105] Step 305: In response to the first session key matching the second session key, determine the first communication content using the first session key.
[0106] Step 306: Use the first session key to encrypt the first communication content to obtain first encrypted content.
[0107] Step 307: Send the first encrypted content to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
[0108] The first communication end uses the first session key to encrypt the first communication content to obtain the first encrypted content, and sends the first encrypted content to the second communication end. Since the first session key matches the second session key, the second communication end uses the second session key to decrypt the first encrypted content to obtain the accurate first communication content.
[0109] In one scheme of an embodiment of the present invention, a first session key is used to communicate with a second communication terminal, including: receiving second encrypted content sent by the second communication terminal; wherein the second encrypted content is obtained by the second communication terminal encrypting the second content using the second session key; using the first session key, encrypting the second encrypted content to obtain second communication content; and performing information processing on the second communication content.
[0110] The second communication end encrypts the second encrypted content using the second session key and sends the second encrypted content to the first communication end. Since the first session key matches the second session key, the first communication end decrypts the second encrypted content using the first session key to obtain accurate second communication content.
[0111] In the solution of the embodiment of the present invention, when the session keys of the two communication terminals match, the first communication terminal and the second communication terminal use their respective session keys to encrypt the communication content and send the encrypted content to the other communication terminal. Or use their respective session keys to decrypt the received encrypted content to obtain the communication content.
[0112] The embodiment of the present invention proposes a communication method of dynamic key based on ECC (elliptic curve cryptography). The method takes advantage of the small key size of ECC to reduce transmission delay and generates a unique session key at the beginning of each data transmission session to enhance the security of key management. The method includes: a dynamic key exchange process and a content encryption process.
[0113] The dynamic key exchange process includes the following steps:
[0114] Step S11, initialization: The first communication end and the second communication end negotiate to use a public elliptic curve parameter and a base point parameter. These parameters can be pre-defined in the application or shared between the two parties in a secure manner. The first communication end can be a terminal and the second communication end can be a server.
[0115] Step S12, key pair generation: When the terminal (first communication end) needs to establish a new data transmission session with the server (second communication end), the terminal and the server independently generate a pair of temporary ECC public and private keys. The ECC algorithm can provide security comparable to that of a larger RSA (asymmetric encryption algorithm) key at a smaller key size, thus helping to reduce computational complexity.
[0116] Step S13, public key exchange: the terminal sends the first public key to the server in a secure manner, and the server also sends the second public key to the terminal. This step usually uses existing security protocols to ensure the security of the public key exchange process.
[0117] Step S14, session key generation: using the ECDH algorithm key exchange algorithm, the terminal uses its own first private key and the server's second public key to calculate a shared first session key.
[0118] The server also uses its second private key and the first public key of the terminal to calculate and obtain the second session key. This process uses the properties of elliptic curve cryptography. Only two parties with corresponding private keys can calculate the same first session key and second session key.
[0119] Step S15, key confirmation: In order to confirm that the session keys calculated by both parties are consistent, the two parties may exchange certain known data or hash values encrypted by the session key.
[0120] Step S16, using the key: After the session key is confirmed to be correct, it is used in the AES (Advanced Encryption Standard) algorithm to encrypt the data. This ensures that the data is sent to the server after being encrypted by the terminal, and remains encrypted throughout the transmission process until it is decrypted by the server using the same session key.
[0121] The advantage of dynamic key exchange is that it generates a unique key for each session, greatly enhancing security. If the session key is leaked, it will only affect a single communication and will not threaten other communication sessions. In addition, using the efficient characteristics of ECC, the key size is reduced, and the computing and storage requirements are correspondingly reduced, while still maintaining a high level of security.
[0122] The content encryption process uses the Advanced Encryption Standard (AES) to encrypt the transmitted data, which is achieved through the session key generated by dynamic key exchange. The encryption process is performed at the terminal to ensure that the data is encrypted before being sent to the server, thereby protecting the data from being eavesdropped or tampered with by man-in-the-middle attackers.
[0123] It also provides a two-way authentication mechanism. On the basis of dynamic key exchange, DSA (Digital Signature Algorithm) is added to achieve two-way authentication between the terminal and the server, ensuring the authenticity of the identities of both parties in data transmission and preventing attacks by forged identities.
[0124] The content encryption exchange process includes the following steps:
[0125] Step S21, generation of session key: before content encryption, the terminal and the server jointly generate the same session key through a dynamic key exchange protocol. The session key is symmetric, that is, the same key is used for encryption and decryption.
[0126] Step S22, prepare data: The original data to be encrypted needs to be formatted, which may include padding operations to ensure that the length of the data block is an integer multiple of the length required by the AES algorithm. AES encryption usually encrypts in blocks of 128 bits (16 bytes). For special requirements on data format, such as JSON objects, it may be necessary to serialize them into string form.
[0127] Step S23, select encryption mode: AES supports multiple encryption modes, such as ECB (Electronic Codebook), CBC (Cipher Block Chaining), CFB (Cipher Feedback), OFB (Output FeedBack), and CTR (Counter Mode). Select one of the modes to suit the specific requirements of network applications. Among them, CBC mode is a common choice because it handles the encryption of different data blocks more securely.
[0128] Step S24, use of initialization vector: In encryption modes such as CBC mode, an initialization vector is used for each encryption session, which works together with the session key to encrypt the first data block, so as to ensure that the encrypted ciphertext is unique in different sessions, thus enhancing encryption security. The initialization vector is usually random.
[0129] Step S25, encryption process: Use the session key and initialization vector to encrypt the terminal data in blocks according to the AES algorithm and the selected mode. Each plaintext block performs a specific operation with the previous ciphertext block, such as an XOR operation in CBC mode. Then encrypt. For the first data block, use the initialization vector instead of the previous ciphertext block and perform a specific operation with the first data block.
[0130] Step S26, output ciphertext: After continuously processing all data blocks, the output formed is the encrypted ciphertext. This ciphertext should not reveal any information about the original plaintext.
[0131] Step S27, transmitting ciphertext: The encrypted ciphertext is sent to the server via the network. Since AES encryption is used, even if it is intercepted during transmission, the attacker cannot decrypt and obtain the plaintext information without the corresponding session key.
[0132] Step S28, server-side decryption: After receiving the ciphertext, the server uses the same session key and initialization vector in reverse order to restore the original plaintext data using the AES decryption algorithm.
[0133] In the entire encryption process, the most critical thing is to protect the security of the session key, because with the session key, the communication content can be decrypted. In addition, the embodiment of the present invention also proposes to use Web Workers to perform encryption tasks to avoid performing complex encryption calculations in the main thread, thereby avoiding slowing down the performance of terminal applications. Based on the parallel processing strategy of WebWorkers, the calculation tasks of the key exchange process and the data encryption process are executed in the background thread to avoid the encryption process blocking the main thread and reduce the impact on the user experience.
[0134] Compared with the prior art, the embodiments of the present invention provide a more secure and effective terminal data encryption and transmission solution. Through dynamic key exchange and terminal encryption, the security of the data transmission process is significantly improved. The two-way verification mechanism further enhances the reliability of identity authentication. At the same time, the performance optimization strategy ensures the efficiency of the encryption process and maintains a smooth user experience.
[0135] Figure 4 is a schematic diagram of the structure of a communication device provided by an embodiment of the present invention, such as Figure 4 As shown, applied to a first communication terminal, the device includes:
[0136] The public key sending module 401 is used to generate a first public key and a first private key by using a first algorithm, and send the first public key to the second communication terminal;
[0137] The public key receiving module 402 is used to receive the second public key sent by the second communication terminal;
[0138] A key generation module 403, configured to generate a first session key according to the first private key and the second public key using a second algorithm corresponding to the first algorithm;
[0139] A matching module 404 is used to determine whether the first session key matches the second session key; wherein the second session key is generated by the second communication end using the second algorithm according to the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm;
[0140] The communication module 405 is used to communicate with the second communication end using the first session key in response to the first session key matching the second session key.
[0141] Optionally, the matching module 404 is specifically configured to:
[0142] Negotiating with the second communication end to determine the preset data;
[0143] Receiving first confirmation data sent by the second communication end; wherein the first confirmation data is obtained by the second communication end encrypting the preset data using the second session key;
[0144] Using the first session key, decrypting the first confirmation data to obtain first decrypted data;
[0145] In response to the first decrypted data matching the preset data, it is determined that the first session key matches the second session key, and notification information indicating the key matching is sent to the second communication terminal.
[0146] Optionally, the matching module 404 is specifically configured to:
[0147] Negotiating with the second communication end to determine the preset data;
[0148] Using the first session key, encrypting the preset data to obtain second confirmation data;
[0149] sending the second confirmation data to the second communication end, so that the second communication end determines whether the first session key matches the second session key according to the second confirmation data;
[0150] In response to receiving notification information indicating key matching sent by the second communication end, it is determined that the first session key matches the second session key.
[0151] Optionally, the communication module 405 is specifically used for:
[0152] determining first communication content;
[0153] Using the first session key, encrypting the first communication content to obtain first encrypted content;
[0154] The first encrypted content is sent to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
[0155] Optionally, the communication module 405 is specifically used for:
[0156] Receiving second encrypted content sent by the second communication terminal; wherein the second encrypted content is encrypted by the second communication terminal using the second session key;
[0157] Using the first session key, encrypting the second encrypted content to obtain the second communication content;
[0158] Information processing is performed on the second communication content.
[0159] Optionally, it also includes:
[0160] A judgment module, used to determine whether the first communication terminal and / or the second communication terminal meets the key refresh condition;
[0161] In response to the first communication terminal and / or the second communication terminal meeting the key refresh condition, the steps of using the first algorithm to generate the first public key and the first private key and sending the first public key to the second communication terminal are re-executed.
[0162] Optionally, the first algorithm is an elliptic curve cryptography algorithm, and the second algorithm is an elliptic curve Diffie-Hellman key exchange algorithm.
[0163] An embodiment of the present invention provides an electronic device, including:
[0164] one or more processors;
[0165] The storage device is used to store one or more programs. When the one or more programs are executed by one or more processors, the one or more processors implement the method of any of the above embodiments.
[0166] An embodiment of the present invention provides a computer program product, including a computer program. When the computer program is executed by a processor, the communication method in the embodiment of the present invention is implemented.
[0167] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0168] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0169] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0170] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0171] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0172] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0173] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, they may be described as: a public key sending module, a public key receiving module, a key generating module, a matching module, and a communication module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the public key sending module may also be described as "a module that generates a first public key and a first private key using a first algorithm, and sends the first public key to a second communication terminal".
[0174] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0175] Generate a first public key and a first private key using a first algorithm, and send the first public key to the second communication end;
[0176] Receiving a second public key sent by the second communication end;
[0177] Generate a first session key using a second algorithm corresponding to the first algorithm and based on the first private key and the second public key;
[0178] Determine whether the first session key matches a second session key; wherein the second session key is generated by the second communication end using the second algorithm according to the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm;
[0179] In response to the first session key matching the second session key, communicating with the second communication end using the first session key.
[0180] According to the technical solution of the embodiment of the present invention, the first communication terminal and the second communication terminal respectively use the first algorithm to generate their own public key and private key, and send their respective public keys to the other communication terminal. The first communication terminal uses the second algorithm to generate a first session key based on its own private key and the public key of the other terminal. The second communication terminal uses the second algorithm to generate a second session key based on its own private key and the public key of the other terminal. The cryptographic properties of the first algorithm and the second algorithm ensure that the first communication terminal and the second communication terminal can obtain matching session keys. When the first communication terminal and the second communication terminal determine that the first session key matches the second session key, they use their respective session keys to communicate, ensuring that the communication content can be effectively encrypted and decrypted. Therefore, the solution of the embodiment of the present invention can achieve secure and reliable data communication.
[0181] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A communication method, characterized in that: Applied to the first communication end, comprising: Generate a first public key and a first private key using a first algorithm, and send the first public key to the second communication end; Receiving a second public key sent by the second communication end; Generate a first session key using a second algorithm corresponding to the first algorithm and based on the first private key and the second public key; Determine whether the first session key matches a second session key; wherein the second session key is generated by the second communication end using the second algorithm according to the second private key and the first public key; the second private key and the second public key are generated by the second communication end using the first algorithm; In response to the first session key matching the second session key, communicating with the second communication end using the first session key.
2. The method according to claim 1, characterized in that The determining whether the first session key matches the second session key comprises: Negotiating with the second communication end to determine preset data; receiving first confirmation data sent by the second communication end; wherein the first confirmation data is obtained by the second communication end encrypting the preset data using the second session key; Using the first session key, decrypting the first confirmation data to obtain first decrypted data; In response to the first decrypted data matching the preset data, it is determined that the first session key matches the second session key, and notification information indicating the key matching is sent to the second communication terminal.
3. The method according to claim 1, characterized in that: The determining whether the first session key matches the second session key comprises: Negotiating with the second communication end to determine preset data; Using the first session key, encrypting the preset data to obtain second confirmation data; sending the second confirmation data to the second communication end, so that the second communication end determines whether the first session key matches the second session key according to the second confirmation data; In response to receiving the notification information indicating key matching sent by the second communication end, it is determined that the first session key matches the second session key.
4. The method according to claim 1, characterized in that: The communicating with the second communication end by using the first session key includes: determining first communication content; Using the first session key, encrypting the first communication content to obtain first encrypted content; The first encrypted content is sent to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
5. The method according to claim 1, characterized in that The communicating with the second communication end by using the first session key includes: receiving second encrypted content sent by the second communication end; wherein the second encrypted content is encrypted by the second communication end using the second session key; Using the first session key, encrypting the second encrypted content to obtain second communication content; Perform information processing on the second communication content.
6. The method according to claim 1, characterized in that Also includes: Determining whether the first communication end and / or the second communication end meets a key refresh condition; In response to the first communication terminal and / or the second communication terminal meeting the key refresh condition, the step of using the first algorithm to generate a first public key and a first private key, and sending the first public key to the second communication terminal is re-executed.
7. The method according to claim 1, characterized in that The first algorithm is an elliptic curve cryptography algorithm, and the second algorithm is an elliptic curve Diffie-Hellman key exchange algorithm.
8. A communication device, characterized in that: Applied to the first communication end, comprising: A public key sending module, used to generate a first public key and a first private key by using a first algorithm, and send the first public key to the second communication end; A public key receiving module, used to receive a second public key sent by the second communication end; a key generation module, configured to generate a first session key according to the first private key and the second public key by using a second algorithm corresponding to the first algorithm; a matching module, configured to determine whether the first session key matches a second session key; wherein the second session key is generated by the second communication terminal using the second algorithm, according to a second private key and the first public key; and the second private key and the second public key are generated by the second communication terminal using the first algorithm; The communication module is used for communicating with the second communication end by using the first session key in response to the first session key matching the second session key.
9. The device according to claim 8, characterized in that The matching module is specifically used for: Negotiating with the second communication end to determine preset data; receiving first confirmation data sent by the second communication end; wherein the first confirmation data is obtained by the second communication end encrypting the preset data using the second session key; Using the first session key, decrypting the first confirmation data to obtain first decrypted data; In response to the first decrypted data matching the preset data, it is determined that the first session key matches the second session key, and notification information indicating the key matching is sent to the second communication terminal.
10. The device according to claim 8, characterized in that The matching module is specifically used for: Negotiating with the second communication end to determine preset data; Using the first session key, encrypting the preset data to obtain second confirmation data; sending the second confirmation data to the second communication end, so that the second communication end determines whether the first session key matches the second session key according to the second confirmation data; In response to receiving the notification information indicating key matching sent by the second communication end, it is determined that the first session key matches the second session key.
11. The device according to claim 8, characterized in that The communication module is specifically used for: determining first communication content; Using the first session key, encrypting the first communication content to obtain first encrypted content; The first encrypted content is sent to the second communication end, so that the second communication end uses the second session key to decrypt the first encrypted content to obtain the first communication content.
12. The device according to claim 8, characterized in that The communication module is specifically used for: receiving second encrypted content sent by the second communication end; wherein the second encrypted content is encrypted by the second communication end using the second session key; Using the first session key, encrypting the second encrypted content to obtain second communication content; Perform information processing on the second communication content.
13. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
14. A computer readable medium having a computer program stored thereon, characterized in that When the program is executed by a processor, the method described in any one of claims 1 to 7 is implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
