Blockchain-based message transmission method, device, equipment and readable storage medium
Through the blockchain-based message transmission method, the key agreement algorithm and the hash algorithm are used to generate the message key, and the messages in instant messaging are encrypted, which solves the security vulnerability problem caused by the centralized storage of keys and achieves high security. message transmission.
Patent Information
- Application Number
- CN202111182077.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-11
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-10-11
AI Technical Summary
In existing instant messaging applications, the unified storage of keys is managed by the service provider and stored centrally on the server. There are security loopholes that easily lead to message leakage and poor security.
Adopt a blockchain-based message transmission method, by determining the first private key and the second public key of the second device, use a key agreement algorithm to generate a master key, and convert it into a chain key, which is processed based on a hash algorithm , generate a message key, encrypt the message to be transmitted, transmit it to the second device, and ensure the security of message transmission through asymmetric keys and complex encryption methods.
It alleviates security loopholes in the message delivery process, avoids message loss and leakage, improves security, and is user-controllable. The message is sent directly to the recipient without involving any chain server.
Smart Images

Figure CN113918971B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a message transmission method, apparatus, device and readable storage medium based on blockchain. Background Art
[0002] With the rapid development of Internet technology, various instant messaging applications are increasingly used in all aspects of life and work. In the instant messaging scenario, users are increasingly concerned about the security of data and messages. Therefore, many instant messaging applications will encrypt messages sent by users to ensure the safe sending and receiving of messages and avoid message leakage.
[0003] In the related art, instant messaging applications are equipped with an end-to-end encryption system. Instant messaging applications will set a default key or allow users to set the key themselves, and store the key on the server that provides message transmission services. In this way, when the user has a message sending demand, the stored key is used to encrypt the message, and the encrypted message is transmitted to the recipient of the message, and the recipient uses the key to decrypt and view the encrypted message.
[0004] In the process of implementing this application, the applicant found that the related technology has at least the following problems:
[0005] The unified storage of keys is managed by the service provider of the instant messaging application and is centrally stored on the server. This has security vulnerabilities and is prone to theft, which can lead to message leakage during transmission, and has poor security. Summary of the invention
[0006] In view of this, the present application provides a blockchain-based message transmission method, device, equipment and readable storage medium, the main purpose of which is to solve the problem that the current key storage is managed by the service provider of the instant messaging application and centrally stored on the server, which has security vulnerabilities and is prone to theft, resulting in message leakage during transmission and poor security.
[0007] According to the first aspect of the present application, a message transmission method based on blockchain is provided, the method is applied to a first device, and the method includes:
[0008] Determine a first private key and a second public key of a second device, wherein the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service;
[0009] Calculate the first private key and the second public key using a key agreement algorithm to generate a master key;
[0010] Convert the master key into a chain key, and process the chain key based on a hash algorithm to obtain a message key;
[0011] The message to be transmitted is encrypted based on the message key to generate a message ciphertext, and the message ciphertext is transmitted to the second device so that the second device determines the first public key of the first device and the second private key of the second device, and the first public key and the second private key are processed using the key agreement algorithm and the hash algorithm to generate a decryption key, and the message ciphertext is decrypted based on the decryption key to obtain the message to be transmitted.
[0012] Optionally, before determining the first private key and the second public key of the second device, the method further includes:
[0013] In response to a user's application installation request, obtaining an asymmetric key pair issued by a target client for installation based on the application installation request, wherein the asymmetric key pair includes the first private key and the first public key;
[0014] Sending the first public key to the network provider;
[0015] Encrypting a preset verification message based on the first private key to generate a verification ciphertext, and sending the verification ciphertext to the network provider, so that the network provider uses the first public key to decrypt the verification ciphertext;
[0016] Correspondingly, when the network provider successfully decrypts the verification ciphertext using the first public key, the network provider issues a digital certificate to the first device, and stores the digital certificate and the first public key in the blockchain, where the digital certificate is used to indicate the identity of the first device and to indicate that the first public key has passed verification;
[0017] When the network provider fails to decrypt the verification ciphertext using the first public key, the network provider sends a verification failure reminder to the first device, so that the first device re-provides the first public key to the network provider.
[0018] Optionally, determining the first private key and the second public key of the second device includes:
[0019] Acquire the first private key from a first storage medium of the first device;
[0020] Sending the second device identification of the second device to the network provider, so that the network provider queries the second digital certificate corresponding to the second device identification, obtains the second public key bound to the second digital certificate, and returns the second public key to the first device;
[0021] Receive the second public key returned by the network provider, and store the second public key in the first storage medium.
[0022] Optionally, converting the master key into a chain key, and processing the chain key based on a hash algorithm to obtain a message key includes:
[0023] Calculating the master key using a message digest algorithm to obtain the chain key;
[0024] Determine the hash algorithm, where the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm;
[0025] Querying a round number, and combining the round number and the chain key into a character string to be processed, wherein the round number indicates the number of times a message key is generated during a message transmission process between the first device and the second device;
[0026] The hash message authentication code algorithm and the secure hash algorithm are used to calculate the character string to be processed to obtain the message key.
[0027] Optionally, after encrypting the message to be transmitted based on the message key to generate a message ciphertext, and transmitting the message ciphertext to the second device, the method further includes:
[0028] In response to a message sending request from a user, determine a round number used when transmitting the ciphertext of the message to the second device, and update the round number using a ratchet algorithm;
[0029] The updated round number and the chain key are combined into a new string, and the new string is calculated using the hash message authentication code algorithm and the secure hash algorithm to obtain a new message key;
[0030] The message indicated by the message sending request is encrypted based on the new message key to generate a new message ciphertext, and the new message ciphertext is transmitted to the second device so that the second device determines the first public key and the second private key, uses the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key, and decrypts the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
[0031] Optionally, the second device determines the first public key of the first device and the second private key of the second device, including:
[0032] The second device obtains the second private key from a second storage medium of the second device;
[0033] The second device sends the first device identification of the first device to the network provider, so that the network provider queries the first digital certificate corresponding to the first device identification, obtains the first public key bound to the first digital certificate, and returns the first public key to the second device;
[0034] The second device receives the first public key returned by the network provider, and stores the first public key in the second storage medium.
[0035] Optionally, the adopting the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key includes:
[0036] The second device calculates the first public key and the second private key using a key agreement algorithm to generate the master key;
[0037] The second device calculates the master key using an information digest algorithm to obtain the chain key;
[0038] The second device determines the hash algorithm, where the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm;
[0039] The second device queries a round number, and combines the round number and the chain key into a character string to be processed, wherein the round number indicates the number of times a message key is generated during a message transmission process between the first device and the second device;
[0040] The second device uses the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the decryption key.
[0041] According to a second aspect of the present application, a message transmission device based on blockchain is provided, and the device is applied to a first device, and the device includes:
[0042] A determination module, configured to determine a first private key and a second public key of a second device, wherein the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service;
[0043] A calculation module, used to calculate the first private key and the second public key using a key agreement algorithm to generate a master key;
[0044] A processing module, used to convert the master key into a chain key, and process the chain key based on a hash algorithm to obtain a message key;
[0045] A transmission module is used to encrypt the message to be transmitted based on the message key to generate a message ciphertext, and transmit the message ciphertext to the second device so that the second device can determine the first public key of the first device and the second private key of the second device, use the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key, and decrypt the message ciphertext based on the decryption key to obtain the message to be transmitted.
[0046] Optionally, the device further comprises:
[0047] an acquisition module, configured to, in response to a user's application installation request, acquire an asymmetric key pair issued by a target client for installation based on the application installation request, wherein the asymmetric key pair includes the first private key and the first public key;
[0048] A sending module, used for sending the first public key to the network provider;
[0049] an encryption module, configured to encrypt a preset verification message based on the first private key to generate a verification ciphertext, and send the verification ciphertext to the network provider so that the network provider decrypts the verification ciphertext using the first public key;
[0050] Correspondingly, the storage module is used for, when the network provider successfully decrypts the verification ciphertext using the first public key, the network provider issues a digital certificate to the first device, and stores the digital certificate and the first public key in the blockchain, wherein the digital certificate is used to indicate the identity of the first device and to indicate that the first public key has passed the verification;
[0051] The sending module is further configured to, when the network provider fails to decrypt the verification ciphertext using the first public key, send a verification failure reminder to the first device so that the first device re-provides the first public key to the network provider.
[0052] Optionally, the determination module is also used to obtain the first private key from the first storage medium of the first device; send the second device identification of the second device to the network provider, so that the network provider queries the second digital certificate corresponding to the second device identification, obtains the second public key bound to the second digital certificate, and returns the second public key to the first device; receives the second public key returned by the network provider, and stores the second public key in the first storage medium.
[0053] Optionally, the processing module is used to calculate the master key using an information digest algorithm to obtain the chain key; determine the hash algorithm, the hash algorithm including a hash message authentication code algorithm and a secure hash algorithm; query the round number, and combine the round number and the chain key into a character string to be processed, wherein the round number indicates the number of times a message key is generated during the message transmission process between the first device and the second device; and use the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the message key.
[0054] Optionally, the device further comprises:
[0055] an updating module, configured to determine, in response to a message sending request from a user, a round number used when transmitting the ciphertext of the message to the second device, and to update the round number using a ratchet algorithm;
[0056] The calculation module is further used to combine the updated round number and the chain key into a new string, and use the hash message authentication code algorithm and the secure hash algorithm to calculate the new string to obtain a new message key;
[0057] The transmission module is also used to encrypt the message indicated by the message sending request based on the new message key to generate a new message ciphertext, and transmit the new message ciphertext to the second device, so that the second device determines the first public key and the second private key, uses the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key, and decrypts the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
[0058] Optionally, the transmission module is also used for the second device to obtain the second private key in the second storage medium of the second device; the second device sends the first device identification of the first device to the network provider, so that the network provider queries the first digital certificate corresponding to the first device identification, obtains the first public key bound to the first digital certificate, and returns the first public key to the second device; the second device receives the first public key returned by the network provider, and stores the first public key in the second storage medium.
[0059] Optionally, the transmission module is also used for the second device to use a key agreement algorithm to calculate the first public key and the second private key to generate the master key; the second device uses an information digest algorithm to calculate the master key to obtain the chain key; the second device determines the hash algorithm, and the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm; the second device queries the round number, and combines the round number and the chain key into a character string to be processed, and the round number indicates the number of times a message key is generated during the message transmission process between the first device and the second device; the second device uses the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the decryption key.
[0060] According to a third aspect of the present application, a device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.
[0061] According to a fourth aspect of the present application, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.
[0062] Through the above technical scheme, the present application provides a blockchain-based message transmission method, apparatus, device and readable storage medium. The first device of the present application determines a first private key and a second public key of the second device, uses a key agreement algorithm to calculate the first private key and the second public key, generates a master key, and converts the master key into a chain key. The chain key is processed based on a hash algorithm to obtain a message key, and the message to be transmitted is encrypted based on the message key to generate a message ciphertext, which is transmitted to the second device. Blockchain, asymmetric keys and complex message encryption methods are used to grant users control permissions, alleviate security vulnerabilities in the current message transmission process, and can send messages directly to the recipient without involving any chain server, thereby avoiding message loss and leakage, and having high security.
[0063] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0065] Figure 1 A schematic diagram of a message transmission method based on blockchain provided in an embodiment of the present application is shown;
[0066] Figure 2A An interactive schematic diagram of a blockchain-based message transmission method provided in an embodiment of the present application is shown;
[0067] Figure 2B An interactive schematic diagram of a blockchain-based message transmission method provided in an embodiment of the present application is shown;
[0068] Figure 2C An interactive schematic diagram of a blockchain-based message transmission method provided in an embodiment of the present application is shown;
[0069] Figure 3A A schematic diagram of the structure of a message transmission device based on blockchain provided in an embodiment of the present application is shown;
[0070] Figure 3B A schematic diagram of the structure of a message transmission device based on blockchain provided in an embodiment of the present application is shown;
[0071] Figure 3C A schematic diagram of the structure of a message transmission device based on blockchain provided in an embodiment of the present application is shown;
[0072] Figure 4 A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0073] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0074] The present application embodiment provides a message transmission method based on blockchain, such as Figure 1 As shown, the method includes:
[0075] 101. Determine a first private key and a second public key of a second device, where the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service.
[0076] 102. Use a key agreement algorithm to calculate the first private key and the second public key to generate a master key.
[0077] 103. Convert the master key into a chain key, process the chain key based on a hash algorithm, and obtain a message key.
[0078] 104. Encrypt the message to be transmitted based on the message key to generate a message ciphertext, and transmit the message ciphertext to the second device so that the second device can determine the first public key of the first device and the second private key of the second device, use the key agreement algorithm and the hash algorithm to process the first public key and the second private key, generate a decryption key, and decrypt the message ciphertext based on the decryption key to obtain the message to be transmitted.
[0079] The method provided in the embodiment of the present application is that the first device determines the first private key and the second public key of the second device, uses the key agreement algorithm to calculate the first private key and the second public key, generates a master key, and converts the master key into a chain key, processes the chain key based on the hash algorithm to obtain a message key, encrypts the message to be transmitted based on the message key, generates a message ciphertext, and transmits the message ciphertext to the second device. Blockchain, asymmetric keys and complex message encryption methods are used to grant users control permissions, alleviate security vulnerabilities in the current message transmission process, and can send messages directly to the recipient without involving any chain server, avoiding message loss and leakage, and having high security.
[0080] The present application embodiment provides a message transmission method based on blockchain, such as Figure 2A As shown, the method involves interaction between a first device and a second device, including:
[0081] 201. A first device determines a first private key and a second public key of a second device.
[0082] In the instant messaging scenario, users are increasingly concerned about their data privacy issues. Current applications are end-to-end encryption systems that rely on service providers to control the server. The encryption and decryption keys are provided by the service provider, and the keys are managed by the service provider, which has security vulnerabilities and is uncontrollable by the user. Although the public key infrastructure mechanism can be used to circumvent the problem, it does cost a lot of money and resources. Therefore, this application proposes a message transmission based on blockchain, which realizes end-to-end communication based on blockchain. When the user downloads and installs the communication program, a pair of asymmetric keys is created for the user, and the message is encrypted based on the asymmetric key. The ratchet method is used to continuously update the intermediate parameters involved in the asymmetric key encryption process. At the same time, the recipient also needs to decrypt and view the message, and the key is sent to the user, giving the user control authority. Based on blockchain, asymmetric keys and complex message encryption methods, the security vulnerabilities in the current message transmission process are alleviated, and the message can be sent directly to the recipient without involving any chain server to avoid message loss.
[0083] Among them, this application involves an end-to-end message transmission process and involves the field of artificial intelligence. For example, in the field of smart medical care, with the help of the blockchain-based message transmission method in this application, message transmission between multiple parties such as doctors and patients, doctors and doctors, hospitals and hospitals, and hospitals and institutions can be realized. Therefore, it is assumed that the sender of the message is the first device and the receiver of the message is the second device. In order to realize the encryption operation during the message transmission process, this application will generate a pair of asymmetric keys for the user in advance and store them. The process of generating asymmetric keys involves the interaction between the device and the network provider. The specific generation process is as follows:
[0084] The network provider is the party that provides communication services, which can be a chat server, cloud server, etc. The network provider can be an independent server, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and cloud servers that provide basic cloud computing servers such as big data and artificial intelligence platforms. The user holding the first device will download the communication application. After downloading, in response to the user's application installation request, the first device will obtain the asymmetric key pair issued by the target client based on the application installation request. The asymmetric key pair includes a first private key and a first public key. The first private key is held by the user himself, and the first public key is shared with the network provider and the external device so that the network provider can verify the first public key later. The external device interacts with the first device based on the first public key. Therefore, the first device sends the first public key to the network provider.
[0085] Next, the first device encrypts the preset verification message based on the first private key, generates a verification ciphertext, and sends the verification ciphertext to the network provider, so that the network provider uses the first public key to decrypt the verification ciphertext, so that the network provider verifies whether the first public key is valid, and avoids the subsequent communication process being blocked due to the illegality of the uploaded first public key. Among them, since the asymmetric key pair has the characteristics of mutual encryption and decryption, the first device needs to generate a verification ciphertext based on the first private key in the asymmetric key pair, and send the verification ciphertext to the network provider, so that the network provider decrypts the verification ciphertext based on the first public key it holds, and determines whether the first public key is verified based on whether the decryption is successful. Specifically, when generating the verification ciphertext, the first device can select a certain string as the preset verification message, encrypt the string with the first private key, and obtain the verification ciphertext. The string can be the MAC (Media Access Control) address of the first device, the IP (Internet Protocol) address, etc., and this application does not specifically limit this.
[0086] Correspondingly, for the network provider, after receiving the verification ciphertext of the first device, the network provider starts to decrypt the verification ciphertext based on the first public key shared by the first device to verify the legitimacy of the first public key. When the network provider successfully decrypts the verification ciphertext using the first public key, it means that the first public key is correct and legal, that is, the first public key passes the verification and can issue a digital certificate to the first device. Therefore, the network provider issues a digital certificate to the first device and stores the digital certificate and the first public key in the blockchain for subsequent communication. When the external device can directly obtain the first public key of the first device in the blockchain through the network provider. Among them, the digital certificate is used to indicate the identity of the first device and to indicate that the first public key has passed the verification. When the network provider fails to decrypt the verification ciphertext using the first public key, it means that the first public key is wrong and illegal, that is, the first public key fails to pass the verification and cannot issue a digital certificate to the first device. It is necessary to remind the first device to re-share the first public key. Therefore, the network provider sends a verification failure reminder to the first device so that the first device re-provides the first public key to the network provider.
[0087] In summary, see Figure 2B, the process of creating an asymmetric key pair and verifying the key for the device is as follows: Assuming that the first device is Alice and the second device is Bob, after Alice downloads the application, the application executes [Step 1a] to create a public-private key pair for Alice. Subsequently, Alice executes [Step 1b] to send the public key (Public Key) to the network provider NP (Network Processor), and NP executes [Step 1c] to verify the public key and store the public key in the blockchain after the verification. Next, NP executes [Step 1d] to issue a digital certificate to Alice. Similarly, Bob will also create a public-private key pair after downloading the application. NP verifies the public key and issues a digital certificate. For details, please refer to the process in [Step 2a] to [Step 2d]. Among them Figure 1 Internet refers to the Internet, and Chat Server refers to the chat server. The chat server is also connected to the node of the blockchain in order to obtain the user's public key in the blockchain and apply the public key in the message transmission process. In addition, before Alice sends a message to Bob, Alice will obtain Bob's digital certificate from the chat server. Both ChatServer and NP can verify the authenticity of the digital certificate stored on the blockchain node. NP also provides users with a mechanism to access the blockchain node to verify the recipient's digital certificate.
[0088] By executing the above process, an asymmetric key can be created for each device that downloads and installs the instant messaging application, a digital certificate can be issued, and the public key and data certificate in the asymmetric key can be stored in the blockchain node. Considering that the public key or the secret key in the asymmetric key may also be leaked to the outside world, resulting in the risk of message theft during message transmission, therefore, in this application, not only the sender's key but also the receiver's key is used, thereby utilizing dual keys to ensure the security of message transmission. Therefore, when transmitting a message, the first device will determine the first private key and the second public key of the second device, so as to subsequently generate a message key based on the first private key and the second public key.
[0089] Among them, the first private key is the private key of the first device, and the second public key is obtained by the first device from the network provider that provides message transmission services. Specifically, the first device can obtain the first private key in the first storage medium of the first device, and send the second device identification of the second device to the network provider, so that the network provider queries the second digital certificate corresponding to the second device identification, obtains the second public key bound to the second digital certificate, and returns the second public key to the first device. In this way, the first device receives the second public key returned by the network provider, stores the second public key in the first storage medium, and then the first device can realize the message communication with the second device based on the first public key and the second private key. It should be noted that the decryption key of this application is not stored in ChatServer, so the first storage medium is actually the storage medium used by the user of the first device to store the first public key, or the first storage medium can also be a network medium such as Icloud (cloud disk) and OneDrive (cloud storage), and the second storage medium of the second device is the same, and this application does not specifically limit this.
[0090] 202. The first device calculates the first private key and the second public key using a key agreement algorithm to generate a master key.
[0091] In the embodiment of the present application, after determining the first private key and the second public key, the first device will use the key agreement algorithm to calculate the first private key and the second public key to generate a master key. Since the second device will subsequently use the characteristics of the asymmetric key to generate the same master key using the second private key and the first public key for decrypting the ciphertext, the master key is actually the shared key used for message transmission between the first device and the second device.
[0092] Specifically, ECDH (Elliptic Curves Diffie-Hellman, key agreement algorithm) can be used to generate the master key. Assuming the master key is represented by MasterSecret, the generation process of MasterSecret is represented by Formula 1:
[0093] Formula 1: MasterSecret = ECDH (first private key, second public key)
[0094] 203. The first device converts the master key into a chain key, processes the chain key based on a hash algorithm, and obtains a message key.
[0095] In the embodiment of the present application, after determining the master key, the first device converts the master key into a chain key, processes the chain key based on a hash algorithm, and obtains a message key. The specific process of generating the message key is as follows:
[0096] First, the master key is calculated using the information digest algorithm to obtain the chain key. Then, the hash algorithm is determined. The hash algorithm includes the hash message authentication code algorithm and the secure hash algorithm. The round number is queried, and the round number and the chain key are combined into a string to be processed. The round number indicates the number of times the message key is generated during the message transmission between the first device and the second device. Finally, the hash message authentication code algorithm and the secure hash algorithm are used to calculate the string to be processed to obtain the message key. Specifically, the MasterSecret can be processed using the HKDF (Hash Key Derivation Function) method to generate the chain key, which is represented by ChainKey. Then, the chain key ChainKey is processed using the HMAC (Hash-based Message Authentication Code) and SHA256 (256 hash length) methods to obtain the message key, which is represented by MessageKey. Among them, SHA256 is an algorithm subdivided under SHA-2 (Secure Hash Algorithm 2, a cryptographic hash function algorithm standard). Therefore, the generation process of MessageKey is represented by formula 2:
[0097] Formula 2: MessageKey=HMAC-SHA256(ChainKey, 0×01)
[0098] Among them, "0×01" represents the round number.
[0099] 204. The first device encrypts the message to be transmitted based on the message key, generates a message ciphertext, and transmits the message ciphertext to the second device.
[0100] In the embodiment of the present application, after the message key is generated through the above process, the first device will use the message key to encrypt the message to be transmitted, generate a message ciphertext, and transmit the message ciphertext to the second device. Specifically, the first device uses AES (Advanced Encryption Standard), CBC (Cipher Block Chaining), HMAC, and SHA256 to encrypt the message to be transmitted. Assuming that the message to be transmitted is E and the message ciphertext is C, C is expressed by formula 3 as:
[0101] Formula 3: C = EAES-CBC-HMAC-SHA256 (MessageKey)
[0102] Considering that the second device may not reply to the message, so that the first device needs to resend the message, or the first device needs to send other messages, a chain key update mechanism is set in the first device, and the ratchet algorithm is specifically used to update the chain key, so that the generated message key will also be updated. Specifically, in response to the user's message sending request, the first device determines the round number used when transmitting the message ciphertext to the second device, updates the round number using the ratchet algorithm, and forms a new string with the updated round number and the chain key, and calculates the new string using the hash message authentication code algorithm and the secure hash algorithm to obtain a new message key. Then, the first device encrypts the message indicated by the message sending request based on the new message key, generates a new message ciphertext, and transmits the new message ciphertext to the second device, so that the second device determines the first public key and the second private key, uses the key agreement algorithm and the hash algorithm to process the first public key and the second private key, generates a decryption key, and decrypts the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
[0103] When the ratchet algorithm is used to update the chain key, it is actually necessary to regenerate the chain key and roll it forward. Taking the round number "0×01" as an example, the updated chain key ChainKey = HMAC-SHA256 (ChainKey, 0×02). After the chain key is updated, the first device uses the updated chain key to regenerate the message key, and uses the regenerated message key to encrypt the message to be transmitted, generating a message ciphertext for transmission, ensuring that the sender shown by the first device uses a dynamic key to encrypt the message, ensuring the security of other messages after a session is leaked.
[0104] 205. The second device determines the first public key of the first device and the second private key of the second device, processes the first public key and the second private key using a key agreement algorithm and a hash algorithm to generate a decryption key, decrypts the message ciphertext based on the decryption key, and obtains the message to be transmitted.
[0105] In an embodiment of the present application, after receiving the message ciphertext, the second device determines the first public key of the first device and the second private key of the second device based on the process in the above steps 201 to 203, and processes the first public key and the second private key, that is, the second device obtains the second private key in the second storage medium of the second device, and sends the first device identification of the first device to the network provider, so that the network provider queries the first digital certificate corresponding to the first device identification, obtains the first public key bound to the first digital certificate, and returns the first public key to the second device. Then, the second device receives the first public key returned by the network provider and stores the first public key in the second storage medium. The second device uses the key agreement algorithm to calculate the first public key and the second private key, generates a master key, uses the information digest algorithm to calculate the master key, obtains the chain key, and determines the hash algorithm, queries the round number, and combines the round number and the chain key into a character string to be processed, and uses the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the decryption key.
[0106] In summary, after receiving the message ciphertext, the second device processes the first public key and the second private key to generate a decryption key. The decryption key is actually the message key mentioned above, which can be represented by MessageKey. After that, the message ciphertext is decrypted using the decryption key using AES, CBC, HMAC, and SHA256. Assuming that the message ciphertext is D and the message content is M, M can be represented by formula 4 as:
[0107] Formula 4: M = DAES-CBC-HMAC-SHA256 (MessageKey)
[0108] Through the above process, the message key is generated from the key chain and is continuously updated as the key chain is updated. Furthermore, since the shared key is generated by the device based on the public key and private key, the shared key is not stored on the chat server side and is not shared with others, thereby eliminating the vulnerabilities associated with it. That is, the certificate does not pass through the server, and the sender can directly obtain the recipient's certificate from the blockchain associated with the NP. The encrypted message is then sent directly to the recipient without involving any chain server. This situation is particularly suitable for organization-to-organization messaging, because individual users may not be online all the time and may lose some messages. Specifically, the message transmission process between the first device and the second device in steps 201 to 205 above is as follows, see Figure 2C :
[0109] Assume that the first device is Alice and the second device is Bob. When Alice needs to send a message, she executes [Step 3a] to request Bob's certificate. Subsequently, the chat server returns Bob's certificate to Alice, and Alice executes [Step 3b] to obtain Bob's certificate information and store it locally. Next, Alice executes [Step 3c] to generate MasterSecret, and executes [Step 3d] to generate the chain key ChainKey using HKDF. Further, Alice executes [Step 3e] to produce the message key MessageKey, and executes [Step 3f] to generate the chain key and roll forward, keeping the message key MessageKey updated. Alice executes [Step 3g], encrypts the message using MessageKey, generates ciphertext, and transmits the ciphertext to Bob. Similarly, after receiving the ciphertext, Bob executes [Step 3a'] and [Step 3b'] to obtain Alice's certificate and store it locally, and executes [Step 3h] to decrypt the ciphertext to obtain the message content.
[0110] The method provided in the embodiment of the present application is that the first device determines the first private key and the second public key of the second device, uses the key agreement algorithm to calculate the first private key and the second public key, generates a master key, and converts the master key into a chain key, processes the chain key based on the hash algorithm to obtain a message key, encrypts the message to be transmitted based on the message key, generates a message ciphertext, and transmits the message ciphertext to the second device. Blockchain, asymmetric keys and complex message encryption methods are used to grant users control permissions, alleviate security vulnerabilities in the current message transmission process, and can send messages directly to the recipient without involving any chain server, avoiding message loss and leakage, and having high security.
[0111] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a message transmission device based on blockchain, such as Figure 3A As shown, the device includes: a determination module 301, a calculation module 302, a processing module 303, and a transmission module 304.
[0112] The determination module 301 is used to determine a first private key and a second public key of a second device, wherein the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service;
[0113] The calculation module 302 is used to calculate the first private key and the second public key using a key agreement algorithm to generate a master key;
[0114] The processing module 303 is used to convert the master key into a chain key, and process the chain key based on a hash algorithm to obtain a message key;
[0115] The transmission module 304 is used to encrypt the message to be transmitted based on the message key, generate a message ciphertext, and transmit the message ciphertext to the second device, so that the second device can determine the first public key of the first device and the second private key of the second device, use the key agreement algorithm and the hash algorithm to process the first public key and the second private key, generate a decryption key, and decrypt the message ciphertext based on the decryption key to obtain the message to be transmitted.
[0116] In specific application scenarios, such as Figure 3B As shown, the device also includes: an acquisition module 305, a sending module 306, an encryption module 307 and a storage module 308.
[0117] The acquisition module 305 is used to respond to the user's application installation request and obtain an asymmetric key pair issued by the target client based on the application installation request, wherein the asymmetric key pair includes the first private key and the first public key;
[0118] The sending module 306 is used to send the first public key to the network provider;
[0119] The encryption module 307 is used to encrypt the preset verification message based on the first private key to generate a verification ciphertext, and send the verification ciphertext to the network provider so that the network provider uses the first public key to decrypt the verification ciphertext;
[0120] Correspondingly, the storage module 308 is used for, when the network provider successfully decrypts the verification ciphertext using the first public key, the network provider issues a digital certificate to the first device, and stores the digital certificate and the first public key in the blockchain, wherein the digital certificate is used to indicate the identity of the first device and to indicate that the first public key has passed the verification;
[0121] The sending module 306 is also used for, when the network provider fails to decrypt the verification ciphertext using the first public key, the network provider sends a verification failure reminder to the first device, so that the first device provides the first public key to the network provider again.
[0122] In a specific application scenario, the determination module 301 is also used to obtain the first private key in the first storage medium of the first device; send the second device identification of the second device to the network provider, so that the network provider queries the second digital certificate corresponding to the second device identification, obtains the second public key bound to the second digital certificate, and returns the second public key to the first device; receives the second public key returned by the network provider, and stores the second public key in the first storage medium.
[0123] In a specific application scenario, the processing module 303 is used to calculate the master key using an information digest algorithm to obtain the chain key; determine the hash algorithm, which includes a hash message authentication code algorithm and a secure hash algorithm; query the round number, and combine the round number and the chain key into a string to be processed, wherein the round number indicates the number of times a message key is generated during the message transmission process between the first device and the second device; and use the hash message authentication code algorithm and the secure hash algorithm to calculate the string to be processed to obtain the message key.
[0124] In specific application scenarios, such as Figure 3C As shown, the device also includes: an updating module 309.
[0125] The updating module 309 is used to determine the round number used when transmitting the message ciphertext to the second device in response to the user's message sending request, and update the round number using a ratchet algorithm;
[0126] The calculation module 302 is further used to combine the updated round number and the chain key into a new string, and use the hash message authentication code algorithm and the secure hash algorithm to calculate the new string to obtain a new message key;
[0127] The transmission module 304 is also used to encrypt the message indicated by the message sending request based on the new message key to generate a new message ciphertext, and transmit the new message ciphertext to the second device so that the second device can determine the first public key and the second private key, use the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key, and decrypt the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
[0128] In a specific application scenario, the transmission module 304 is also used for the second device to obtain the second private key in the second storage medium of the second device; the second device sends the first device identification of the first device to the network provider, so that the network provider queries the first digital certificate corresponding to the first device identification, obtains the first public key bound to the first digital certificate, and returns the first public key to the second device; the second device receives the first public key returned by the network provider, and stores the first public key in the second storage medium.
[0129] In a specific application scenario, the transmission module 304 is also used for the second device to use a key agreement algorithm to calculate the first public key and the second private key to generate the master key; the second device uses an information digest algorithm to calculate the master key to obtain the chain key; the second device determines the hash algorithm, and the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm; the second device queries the round number, and combines the round number and the chain key into a character string to be processed, and the round number indicates the number of times a message key is generated during the message transmission process between the first device and the second device; the second device uses the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the decryption key.
[0130] In the apparatus provided by the embodiment of the present application, the first device determines the first private key and the second public key of the second device, adopts the key agreement algorithm to calculate the first private key and the second public key, generates a master key, and converts the master key into a chain key, processes the chain key based on the hash algorithm to obtain a message key, encrypts the message to be transmitted based on the message key, generates a message ciphertext, transmits the message ciphertext to the second device, uses blockchain, asymmetric keys and complex message encryption methods to grant users control permissions, alleviates the security vulnerabilities in the current message transmission process, and can send messages directly to the recipient without involving any chain server, avoiding message loss and leakage, and having high security.
[0131] It should be noted that for other corresponding descriptions of the functional units involved in the blockchain-based message transmission device provided in the embodiment of the present application, please refer to Figure 1 and FIG. 2A to FIG. 2C The corresponding description in will not be repeated here.
[0132] In an exemplary embodiment, see Figure 4, and also provides a computer device, which includes a bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the message transmission method based on blockchain in the above embodiment.
[0133] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the blockchain-based message transmission method.
[0134] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by hardware, or by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0135] Those skilled in the art will appreciate that the accompanying drawings are merely schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily required for implementing the present application.
[0136] Those skilled in the art will appreciate that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more devices different from the implementation scenario. The modules in the above implementation scenario can be combined into one module, or can be further split into multiple sub-modules.
[0137] The above application serial numbers are for description only and do not represent the advantages or disadvantages of the implementation scenarios.
[0138] The above disclosure only discloses several specific implementation scenarios of the present application. However, the present application is not limited thereto, and any changes that can be conceived by technicians in this field should fall within the scope of protection of the present application.
Claims
1. A message transmission method based on blockchain, characterized in that: The method is applied to a first device, comprising: Determine a first private key and a second public key of a second device, wherein the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service; Calculate the first private key and the second public key using a key agreement algorithm to generate a master key; Converting the master key into a chain key, and processing the chain key based on a hash algorithm to obtain a message key, including: calculating the master key using an information digest algorithm to obtain the chain key; determining the hash algorithm, wherein the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm; querying a round number, and combining the round number and the chain key into a character string to be processed, wherein the round number indicates the number of times a message key is generated during a message transmission process between the first device and the second device; and calculating the character string to be processed using the hash message authentication code algorithm and the secure hash algorithm to obtain the message key; Encrypting the message to be transmitted based on the message key to generate a message ciphertext, and transmitting the message ciphertext to the second device, so that the second device determines the first public key of the first device and the second private key of the second device, processes the first public key and the second private key using the key agreement algorithm and the hash algorithm to generate a decryption key, and decrypts the message ciphertext based on the decryption key to obtain the message to be transmitted; Among them, after encrypting the message to be transmitted based on the message key, generating a message ciphertext, and transmitting the message ciphertext to the second device, the method also includes: in response to the user's message sending request, determining the round number used when transmitting the message ciphertext to the second device, and updating the round number using the ratchet algorithm; forming a new string of characters with the updated round number and the chain key, and calculating the new string using the hash message authentication code algorithm and the secure hash algorithm to obtain a new message key; encrypting the message indicated by the message sending request based on the new message key to generate a new message ciphertext, and transmitting the new message ciphertext to the second device, so that the second device determines the first public key and the second private key, processes the first public key and the second private key using the key agreement algorithm and the hash algorithm to generate a decryption key, and decrypts the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
2. The method according to claim 1, characterized in that Before determining the first private key and the second public key of the second device, the method further includes: In response to a user's application installation request, obtaining an asymmetric key pair issued by a target client for installation based on the application installation request, wherein the asymmetric key pair includes the first private key and the first public key; Sending the first public key to the network provider; Encrypting a preset verification message based on the first private key to generate a verification ciphertext, and sending the verification ciphertext to the network provider, so that the network provider uses the first public key to decrypt the verification ciphertext; Correspondingly, when the network provider successfully decrypts the verification ciphertext using the first public key, the network provider issues a digital certificate to the first device, and stores the digital certificate and the first public key in the blockchain, where the digital certificate is used to indicate the identity of the first device and to indicate that the first public key has passed verification; When the network provider fails to decrypt the verification ciphertext using the first public key, the network provider sends a verification failure reminder to the first device, so that the first device re-provides the first public key to the network provider.
3. The method according to claim 1, characterized in that Determining the first private key and the second public key of the second device includes: Acquire the first private key from a first storage medium of the first device; Sending the second device identification of the second device to the network provider, so that the network provider queries the second digital certificate corresponding to the second device identification, obtains the second public key bound to the second digital certificate, and returns the second public key to the first device; Receive the second public key returned by the network provider, and store the second public key in the first storage medium.
4. The method according to claim 1, characterized in that: The second device determines a first public key of the first device and a second private key of the second device, including: The second device obtains the second private key from a second storage medium of the second device; The second device sends the first device identification of the first device to the network provider, so that the network provider queries the first digital certificate corresponding to the first device identification, obtains the first public key bound to the first digital certificate, and returns the first public key to the second device; The second device receives the first public key returned by the network provider, and stores the first public key in the second storage medium.
5. The method according to claim 1, characterized in that The adopting the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key includes: The second device calculates the first public key and the second private key using a key agreement algorithm to generate the master key; The second device calculates the master key using an information digest algorithm to obtain the chain key; The second device determines the hash algorithm, where the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm; The second device queries a round number, and combines the round number and the chain key into a character string to be processed, wherein the round number indicates the number of times a message key is generated during a message transmission process between the first device and the second device; The second device uses the hash message authentication code algorithm and the secure hash algorithm to calculate the character string to be processed to obtain the decryption key.
6. A message transmission device based on blockchain, characterized in that: The device is applied to a first device and includes: A determination module, configured to determine a first private key and a second public key of a second device, wherein the first private key is a private key of the first device, and the second public key is obtained by the first device from a network provider that provides a message transmission service; A calculation module, used to calculate the first private key and the second public key using a key agreement algorithm to generate a master key; a processing module, configured to convert the master key into a chain key, and process the chain key based on a hash algorithm to obtain a message key, wherein the processing module is configured to calculate the master key using an information digest algorithm to obtain the chain key; determine the hash algorithm, wherein the hash algorithm includes a hash message authentication code algorithm and a secure hash algorithm; query a round number, and form a character string to be processed with the round number and the chain key, wherein the round number indicates the number of times a message key is generated during a message transmission process between the first device and the second device; and calculate the character string to be processed using the hash message authentication code algorithm and the secure hash algorithm to obtain the message key; a transmission module, configured to encrypt the message to be transmitted based on the message key to generate a message ciphertext, and transmit the message ciphertext to the second device, so that the second device determines the first public key of the first device and the second private key of the second device, processes the first public key and the second private key using the key agreement algorithm and the hash algorithm to generate a decryption key, and decrypt the message ciphertext based on the decryption key to obtain the message to be transmitted; Wherein, the device further comprises: an updating module, configured to determine, in response to a message sending request from a user, a round number used when transmitting the ciphertext of the message to the second device, and to update the round number using a ratchet algorithm; The calculation module is further used to combine the updated round number and the chain key into a new string, and use the hash message authentication code algorithm and the secure hash algorithm to calculate the new string to obtain a new message key; The transmission module is also used to encrypt the message indicated by the message sending request based on the new message key to generate a new message ciphertext, and transmit the new message ciphertext to the second device so that the second device determines the first public key and the second private key, uses the key agreement algorithm and the hash algorithm to process the first public key and the second private key to generate a decryption key, and decrypts the new message ciphertext based on the decryption key to obtain the message indicated by the message sending request.
7. A device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
