A data encryption method, node device and storage medium
By introducing middleware and encryption algorithm libraries into smart contracts, the complex problem of encryption algorithm modification in the existing technology is solved, and the simplification and efficiency improvement of encryption algorithm modification is achieved.
Patent Information
- Application Number
- CN202010090219.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-12
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-02-12
AI Technical Summary
When changing the transaction data encryption algorithm, the existing technology requires developers to traverse all program code, resulting in a large workload and a complex modification process.
Introduce middleware, including encryption algorithm library, call middleware when running smart contracts, find and use the corresponding encryption algorithm library to encrypt transaction data. You only need to modify the encryption algorithm in the encryption algorithm library, and reduce the modification of the encryption algorithm. workload.
The encryption algorithm modification process is simplified, the workload of developers is reduced, and the efficiency of encryption algorithm changes is improved.
Smart Images

Figure CN111310206B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data encryption method, a node device and a storage medium. Background Art
[0002] When users encrypt transaction data by running program code, the encryption algorithm called in the program code implements the encryption of transaction data. The encryption algorithm is added to the program code in advance by the developer in the form of an encryption algorithm library. When users need to change the encryption algorithm of transaction data, the developer needs to traverse all program codes and change the encryption algorithm at the location where transaction data encryption is required, compile the changed program and provide it to the user, so that the user can use the new encryption algorithm to encrypt transaction data by running the compiled program.
[0003] During the encryption process, users' demand for changing encryption algorithms gradually increases, so simplifying the workload of changing encryption algorithms becomes a problem that needs to be solved. Summary of the invention
[0004] The embodiments of the present invention provide a data encryption method, a node device and a storage medium, which can reduce the workload of modifying the encryption algorithm.
[0005] In a first aspect, an embodiment of the present invention provides a data encryption method, which is applied to a first node device, and includes:
[0006] During the execution of the smart contract, if a first encryption event is triggered, the middleware is called, the first encryption event indicates that the first transaction data is to be encrypted, and the middleware includes an encryption algorithm library; the encryption algorithm library corresponding to the first encryption event is searched in the middleware; the encryption algorithm library is called to encrypt the first transaction data to obtain a first ciphertext.
[0007] In this technical solution, when the first node device is running a smart contract and a first encryption event is triggered, the middleware is called to encrypt the first transaction data using an encryption algorithm in an encryption algorithm library in the middleware. The encryption algorithm library specifies an encryption algorithm for encrypting the first transaction data. If the encryption algorithm is modified, only the encryption algorithm in the encryption algorithm library needs to be modified. Therefore, this data encryption method can reduce the workload of modifying the encryption algorithm.
[0008] In a second aspect, an embodiment of the present invention provides a node device, which is applied to a first node device, and the node device includes a memory, a processor and a communication interface. The memory stores a set of program codes, and the processor calls the program code stored in the memory to execute the method involved in the first aspect.
[0009] In a third aspect, an embodiment of the present invention provides a data encryption device, the encryption device comprising:
[0010] A calling unit, configured to call the middleware if a first encryption event is triggered during the execution of the smart contract, wherein the first encryption event indicates that the first transaction data is to be encrypted, and the middleware includes an encryption algorithm library;
[0011] A search unit, used to search the encryption algorithm library corresponding to the first encryption event in the middleware;
[0012] The calling unit is used to call the encryption algorithm library to encrypt the first transaction data to obtain the first ciphertext.
[0013] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium for storing computer program instructions for a first node device, which includes instructions for executing the program involved in the above-mentioned first aspect.
[0014] By implementing the example of the present invention, when the first node device is running a smart contract, if the first encryption event is triggered, the middleware is called, and then the encryption algorithm corresponding to the first encryption event is found in the middleware, and finally the encryption algorithm library is called to encrypt the first transaction data to obtain the first ciphertext. The encryption algorithm library specifies the encryption algorithm for encrypting the first transaction data. If the encryption algorithm is modified, only the encryption algorithm in the encryption algorithm library needs to be modified, thereby reducing the workload of modifying the encryption algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the background technology, the drawings required for use in the embodiments of the present invention or the background technology will be described below.
[0016] Figure 1 A schematic diagram of the architecture of a blockchain network provided by an embodiment of the present invention;
[0017] Figure 2 A schematic diagram of a data encryption method provided by an embodiment of the present invention;
[0018] Figure 3 A schematic diagram of a flow chart of another data encryption method provided by an embodiment of the present invention;
[0019] Figure 4 A schematic diagram of another data encryption method provided by an embodiment of the present invention;
[0020] Figure 5 A schematic diagram of the structure of a node device provided by an embodiment of the present invention;
[0021] Figure 6A schematic diagram of the structure of a data encryption device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] At present, in the encryption process of transaction data, if the user needs to change the encryption algorithm, the developer can only traverse all the program codes and modify the encryption algorithm at the encryption point in the program code. This modification method can only be operated by the developer and has a large workload. The embodiment of the present application introduces the cryptographic library middleware into data encryption, and proposes a data encryption method, node device and storage medium. In the process of the first node device running a smart contract, if the first encryption event is triggered, the middleware is called, the first encryption event indicates that the first transaction data is encrypted, and the middleware includes an encryption algorithm library; then the first node device searches for the encryption algorithm library corresponding to the first encryption event in the middleware; finally, the first node device calls the encryption algorithm library to encrypt the first transaction data and obtain the first ciphertext. In the data encryption method, when the first node device triggers the first encryption event during the operation of the smart contract, the middleware is called, and the first transaction data is encrypted through the encryption algorithm library of the middleware. The encryption algorithm library specifies the encryption algorithm used when encrypting the first transaction data. The modification of the encryption algorithm of the first transaction data only needs to modify the encryption algorithm in the encryption algorithm library, which can reduce the workload of modifying the encryption algorithm.
[0024] See also Figure 1 , Figure 1 Schematic diagram of the architecture of a blockchain network disclosed in an embodiment of the present invention. Figure 1 As shown, the blockchain network includes a first node device 101 and a second node device 102. Figure 1 The blockchain network shown includes three second node devices 102. Optionally, the blockchain network may include four second node devices 102, five second node devices, etc., which are not limited here. Among them, the first node device 101 and the second node device 102 can both run smart contracts. When the first node device 101 triggers a first encryption event during the execution of the smart contract, the middleware is called, and the first transaction data is encrypted by the encryption algorithm in the encryption algorithm library in the middleware. The second node device 102 can receive the first transaction data and the third transaction data sent by the first node device 101, and verify the third transaction data according to the first transaction data. Figure 1 The blockchain network shown consists of four node devices, which is for illustration only and does not constitute a limitation on the embodiments of the present application.
[0025] Blockchain is a new application model of computer technologies such as distributed data storage, consensus mechanism and encryption algorithm. It is essentially a decentralized database. Blockchain can be composed of multiple serial transaction records (also known as blocks) that are connected and protected by cryptography. The distributed ledger connected by blockchain allows multiple parties to effectively record transactions and can permanently check the transactions (cannot be tampered with).
[0026] Among them, the consensus mechanism refers to the mathematical algorithm for establishing trust and obtaining rights and interests between different nodes in the blockchain network. The consensus mechanism is a mathematical algorithm recognized by all nodes in the blockchain network. The consensus algorithms in the consensus mechanism include but are not limited to the Proof of Work (PoW) algorithm, the Proof of Stake (PoS) algorithm, the Delegated Proof of Stake (DPoS) algorithm, the Practical Byzantine Fault Tolerance (PBFT) algorithm, etc.
[0027] In the data encryption process of the present application, both the first node device and the second node device in the blockchain network store smart contracts, which can trigger the first encryption event by running the smart contract. Among them, a smart contract is a computer protocol designed to disseminate, verify or execute contracts in an information-based manner, allowing trusted transactions without a third party, which are traceable and irreversible. A smart contract is a set of commitments defined in digital form, including protocols on which the contract participants can execute these commitments, and is a piece of code written on the blockchain.
[0028] Encryption algorithms include symmetric encryption algorithms, asymmetric encryption algorithms and hash algorithms. Symmetric encryption algorithms may include but are not limited to DES algorithm, 3DES algorithm, TDEA algorithm, Blowfish algorithm, RC5 algorithm, IDEA algorithm, etc. Asymmetric encryption algorithms may include but are not limited to RSA algorithm, Elgamal algorithm, backpack algorithm, Rabin algorithm, DH algorithm, ECC algorithm, etc. Hash algorithms may include but are not limited to SHA512 algorithm, SHA224 algorithm, SHA384 algorithm, etc.
[0029] Based on the above description, the present application embodiment proposes a method as follows Figure 2 The data encryption method shown in the figure may include the following steps S201-S203:
[0030] S201: When the first node device is running a smart contract and a first encryption event is triggered, the middleware is called.
[0031] The first encryption event indicates that the first transaction data is encrypted, that is, the first encryption event is an event in the smart contract that requires the first transaction data to be encrypted. Middleware is a type of computer software that connects software components and applications. The middleware in this application includes an encryption algorithm library, which includes a symmetric encryption algorithm library, an asymmetric encryption algorithm library, and a hash algorithm library. Each node device specifies the encryption algorithm in the encryption algorithm library in advance, that is, the symmetric encryption algorithm is specified in the symmetric encryption algorithm library, the asymmetric encryption algorithm is specified in the asymmetric encryption algorithm library, and the hash algorithm is specified in the hash algorithm library. That is to say, when an encryption algorithm library in the encryption algorithm library is called, the encryption algorithm in the encryption algorithm library is used to encrypt the transaction data.
[0032] Exemplarily, in the symmetric encryption algorithm library in the encryption algorithm library of the middleware, the symmetric encryption algorithm is specified as the DES algorithm, in the asymmetric encryption algorithm library in the encryption algorithm library, the asymmetric encryption algorithm is specified as the RSA algorithm, and in the hash algorithm library in the encryption algorithm library, the hash algorithm is specified as the SHA512 algorithm. That is, if the first node device calls the symmetric encryption algorithm library in the encryption algorithm library when calling the middleware, the first node device will use the DES algorithm in the symmetric encryption algorithm library to encrypt the transaction data; if the first node device calls the asymmetric encryption algorithm library in the encryption algorithm library, the RSA algorithm in the asymmetric encryption algorithm library will be used to encrypt the transaction data; if the first node device calls the hash algorithm library in the encryption algorithm library, the SHA512 algorithm in the hash algorithm library will be used to encrypt the transaction data.
[0033] The smart contract is stored in the first node device. When the first node device needs to perform an encryption task, it runs the smart contract stored in the node device. When the first node device is running the smart contract, if the first encryption event is triggered, the middleware is called. For example, when the smart contract is running at A, A needs to encrypt the first transaction data, which also means that A is the first encryption event. That is, the first encryption event is triggered at A of the smart contract, and the first node device calls the middleware so that the first node device can continue to call the encryption algorithm library in the middleware.
[0034] S202: The first node device searches for an encryption algorithm library corresponding to the first encryption event in the middleware.
[0035] In the process of writing smart contracts, developers have already specified the type of encryption algorithm used when the first transaction data in the first encryption event is encrypted. For example, if the first encryption event is the first encryption event A, when developers write smart contracts, they specify that the type of encryption algorithm used when the first transaction data A in the first encryption event A in the smart contract is encrypted is a symmetric encryption algorithm. Optionally, the type of encryption algorithm used when the first transaction data A in the first encryption event A is encrypted can be specified in the smart contract as an asymmetric encryption algorithm or a hash algorithm. Therefore, after the first node device calls the middleware, it is necessary to search for the encryption algorithm library corresponding to the first encryption event in the middleware according to the type of encryption algorithm corresponding to the first transaction data in the first encryption event.
[0036] Exemplarily, in a smart contract, if the type of encryption algorithm for the first encryption event A is specified to be an asymmetric encryption algorithm, and the first node device triggers the first encryption event A during the execution of the smart contract, the middleware is called, and then the first node device searches for the encryption algorithm library corresponding to the first encryption event A in the middleware according to the type of encryption algorithm corresponding to the first encryption event A, that is, according to the asymmetric encryption algorithm. Since the type of encryption algorithm corresponding to the first encryption event A is an asymmetric encryption algorithm, the encryption algorithm library found by the first node device in the middleware is an asymmetric encryption algorithm library.
[0037] S203: The first node device calls the encryption algorithm library to encrypt the first transaction data to obtain a first ciphertext.
[0038] Specifically, the first node device calls the encryption algorithm library according to the encryption algorithm library corresponding to the first encryption event found in the middleware, so that the encryption algorithm in the called encryption algorithm library encrypts the first transaction data to obtain the first ciphertext, which is the encrypted transaction data.
[0039] Exemplarily, the first node device finds in S202 that the encryption algorithm library corresponding to the first encryption event A is an asymmetric encryption algorithm library. As described in S201, the asymmetric encryption algorithm used is specified to be the RSA algorithm in the non-encryption algorithm library. Therefore, when the first node device calls the asymmetric encryption algorithm library corresponding to the first encryption event A, the RSA algorithm in the asymmetric encryption algorithm library is used to encrypt the first transaction data A to obtain the first ciphertext A. The first ciphertext A is the transaction data after the first transaction data A is encrypted.
[0040] In the embodiment of the present application, when the first node device is running a smart contract, if the first encryption event is triggered, the middleware is called, and the encryption algorithm library corresponding to the first encryption event is searched in the middleware, and finally the encryption algorithm library is called to encrypt the first transaction data to obtain the first ciphertext. In this way, the encryption algorithm used is specified in a type of encryption algorithm library, that is, when the first node device calls an encryption algorithm library in the middleware, it is determined to use a specific encryption algorithm in the encryption algorithm library to encrypt the first transaction data. Therefore, if the encryption algorithm is modified, the encryption algorithm in the encryption algorithm library can be directly modified, which can reduce the workload of modifying the encryption algorithm.
[0041] See also Figure 3 , Figure 3 For the embodiment of this application Figure 2 Another data encryption method is proposed based on the illustrated embodiment, which may include but is not limited to: S301-S306.
[0042] S301: The first node device receives update information of the target encryption algorithm.
[0043] The target encryption algorithm is a symmetric encryption algorithm, an asymmetric encryption algorithm or a hash algorithm. The middleware includes three encryption algorithm libraries. Each encryption algorithm library specifies the corresponding encryption algorithm. That is, the first node device calls an encryption algorithm library, and determines to use the encryption algorithm corresponding to the encryption algorithm library to encrypt the transaction data. When the user needs to modify the encryption algorithm of the transaction data, the update information of the target encryption algorithm is sent to the first node device, that is, the first node device receives the update information of the target encryption algorithm. The target encryption algorithm corresponds to the encryption algorithm that needs to be modified in the encryption algorithm library. The update information of the target encryption algorithm is used to instruct the first node device to update the encryption algorithm library corresponding to the target encryption algorithm.
[0044] In one implementation, the update information of the target encryption algorithm carries a new encryption algorithm, and the new encryption algorithm is the encryption algorithm corresponding to the target encryption algorithm after the update.
[0045] In one implementation, the update information of the target encryption algorithm carries an identifier of a new encryption algorithm. After receiving the update information of the target encryption algorithm, the node device can determine the new encryption algorithm based on the identifier of the new encryption algorithm carried, thereby modifying the target encryption algorithm to the new encryption algorithm.
[0046] S302: The first node device determines a target configuration file corresponding to a target encryption algorithm in at least one configuration file.
[0047] The middleware includes at least one configuration file, and at least one configuration file includes a configuration file of a symmetric encryption algorithm, a configuration file of an asymmetric encryption algorithm, or a configuration file of a hash algorithm, that is, the middleware may include one, two, or three of the configuration files of a symmetric encryption algorithm, asymmetric encryption algorithm, and hash algorithm, which are not limited here. For example, the middleware only includes the configuration file of the hash algorithm, or the middleware includes the configuration file of the symmetric encryption algorithm and the configuration file of the asymmetric encryption algorithm, etc. The configuration file specifies the encryption algorithm in the encryption algorithm library. For example, the configuration file of the symmetric encryption algorithm specifies that the encryption algorithm used in the symmetric encryption algorithm library is the DES algorithm, the configuration file of the asymmetric encryption algorithm specifies that the encryption algorithm used in the asymmetric encryption algorithm library is the RSA algorithm, and the configuration file of the hash algorithm specifies that the encryption algorithm used in the hash algorithm library is the SHA512 algorithm.
[0048] The first node device receives the update information of the target encryption algorithm, which means that the target encryption algorithm needs to be modified. Since it is an encryption algorithm in the encryption algorithm library specified in the configuration file, the modification of the target encryption algorithm needs to modify the target encryption algorithm in the target encryption algorithm library through the target configuration file, so the first node device needs to first determine the target configuration file corresponding to the target encryption algorithm in at least one configuration file. For example, if the target encryption algorithm is a hash algorithm, the first node device determines that the target configuration file corresponding to the hash algorithm is a hash configuration file in at least one configuration file in the middleware.
[0049] The first node device determines a target configuration file corresponding to the target encryption algorithm in at least one configuration file, and can determine an update path for the target encryption algorithm, namely, the target configuration file.
[0050] S303: The first node device updates the target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file to obtain an updated target encryption algorithm library.
[0051] The configuration file specifies the encryption algorithms in each encryption algorithm library. When the first node device determines the target configuration file corresponding to the target encryption algorithm, the target encryption algorithm library corresponding to the target encryption algorithm is updated based on the update information through the target configuration file to obtain an updated target encryption algorithm library. The encryption algorithm in the updated target encryption algorithm library is a new encryption algorithm, that is, the first node device modifies the encryption algorithm in the target encryption algorithm library to a new encryption algorithm through the target configuration file, thereby realizing the update of the target encryption algorithm library.
[0052] Exemplarily, the target encryption algorithm is a hash algorithm, the target configuration file determined by the first node device is the hash configuration file, and the new encryption algorithm carried by the update information is the SHA224 algorithm. Therefore, the first node device uses the hash configuration file to change the SHA512 algorithm in the hash algorithm library corresponding to the hash algorithm to the SHA224 algorithm based on the update information, thereby updating the hash algorithm library and obtaining an updated hash algorithm library. The encryption algorithm in the updated hash algorithm library is the SHA224 algorithm. When the first node device calls the updated hash algorithm library in the middleware, the SHA224 algorithm in the updated hash algorithm library encrypts the transaction data.
[0053] The node device updates the target encryption algorithm library through the target configuration file and obtains the updated target encryption algorithm library, that is, the encryption algorithm in the target encryption algorithm library is updated. When the target encryption algorithm library is subsequently called, the encryption algorithm in the updated target encryption algorithm library can be used to encrypt the transaction data.
[0054] S304: When the first node device is running the smart contract, if the second encryption event is triggered, the middleware is called.
[0055] The second encryption event indicates that the second transaction data is encrypted, and the second transaction data is transaction data that needs to be encrypted by the first node device. In one implementation, the second encryption event is the first encryption event in S201, the second transaction data is the first transaction data, and before triggering the first encryption event, the first node device receives update information of the target encryption algorithm, and updates the target encryption algorithm library according to the update information through the target configuration file, thereby obtaining an updated target encryption algorithm library.
[0056] In one implementation, the second encryption event is an encryption event after the first encryption event. After the first node device triggers the first encryption event, the first node device receives update information of the target encryption algorithm, and updates the target encryption database according to the update information through the target configuration file to obtain an updated target encryption database.
[0057] After the first node device updates the target encryption database, during the operation of the smart contract, if the second encryption event is triggered, indicating that the second transaction data indicated by the second encryption event needs to be encrypted, the middleware is called. The middleware includes a symmetric encryption algorithm library, an asymmetric encryption algorithm library, and a hash algorithm library. The encryption algorithm in each encryption algorithm library can encrypt the second transaction data. Therefore, when the first node device triggers the second encryption event, the middleware is called to realize the encryption processing of the second transaction data.
[0058] S305: The first node device searches the middleware for an updated target encryption algorithm library corresponding to the second encryption event.
[0059] Specifically, after the first node device calls the middleware, it searches for the updated target encryption algorithm library corresponding to the second encryption event in the middleware, that is, after the first node device updates the target encryption algorithm library, when calling the middleware, it determines the updated target encryption algorithm library corresponding to the second encryption event, so that the encryption algorithm in the updated target encryption algorithm library is subsequently used to encrypt the second transaction data. For example, in a smart contract, the encryption algorithm corresponding to the second encryption event specified in advance is a hash algorithm, and the target encryption algorithm library is a hash algorithm library. When the first node device calls the middleware, the updated target encryption algorithm library corresponding to the second encryption event is found in the middleware as the updated hash algorithm library.
[0060] S306: The first node device calls the updated target encryption algorithm library to encrypt the second transaction data to obtain a second ciphertext.
[0061] After the first node device determines the updated target encryption algorithm library corresponding to the second encryption event, it calls the updated target encryption algorithm library to encrypt the second transaction data using the encryption algorithm in the updated target encryption algorithm library to obtain a second ciphertext, which is the transaction data obtained after the first node device encrypts the second transaction data using the encryption algorithm in the updated target encryption algorithm library.
[0062] For example, the updated target encryption algorithm library is an updated hash algorithm library as shown in S305, so the node device calls the updated hash algorithm library to use the SHA224 algorithm in the updated hash algorithm library to encrypt the second transaction data to obtain a second ciphertext.
[0063] In the embodiment of the present application, the first node device updates the target encryption algorithm library according to the update information of the target encryption algorithm through the configuration file, and after the target encryption algorithm library is updated, when the second encryption event is triggered, the middleware is called, and the second transaction data is encrypted by calling the encryption algorithm in the updated target encryption algorithm library in the middleware to obtain the second ciphertext. In this method, the first node device directly modifies the encryption algorithm in the target encryption algorithm library based on the update information through the configuration file, completes the update of the target encryption algorithm library, reduces the workload of changing the encryption algorithm, and at the same time, after obtaining the updated target encryption algorithm library, when the second encryption event is triggered, the updated target encryption algorithm library in the middleware is called, and the encryption algorithm in the updated target encryption algorithm library is used to encrypt the second transaction data, that is, the encryption algorithm used to encrypt the second transaction data is different from the encryption algorithm used to encrypt the first transaction data.
[0064] Figure 4 The steps that can be performed after S203 include: S401-406.
[0065] S401: The first node device sends the first transaction data and the first ciphertext to each second node device in the blockchain network.
[0066] The second node device is a node device other than the first node device in the blockchain network. The first node device sends the first transaction data and the first ciphertext to each second node device in the blockchain network, so that each second node device can decrypt the first ciphertext.
[0067] S402: Each second node device decrypts the first ciphertext to obtain third transaction data.
[0068] Before encrypting the first transaction data, the first node device and each second node device specify an encryption algorithm for encrypting the first transaction data. Therefore, after receiving the first ciphertext, each second node device can use the pre-specified encryption algorithm to decrypt the first ciphertext to obtain the third transaction data.
[0069] In one implementation, if the second node device fails to decrypt the first ciphertext using the encryption algorithm specified in advance, it means that the first node device uses an encryption algorithm that is inconsistent with the pre-specified one, or the first ciphertext is tampered by a malicious node device during the process of the first node device sending the first ciphertext to the second node device. Therefore, the second node device sends notification information of the failure to decrypt the first ciphertext to the first node device to prompt the first node device to check the encryption algorithm used to encrypt the first transaction data, or to re-encrypt the first transaction data. The second node device sends notification information of the failure to decrypt the first ciphertext to the first node device, which can ensure the correctness of the first ciphertext and improve the security of the first ciphertext.
[0070] S403: Each second node device verifies the third transaction data according to the first transaction data to obtain a verification result.
[0071] The third verification data is obtained by the second node device decrypting the first ciphertext, and the first ciphertext is obtained by the first node device encrypting the first transaction data, so each second node device can verify the third transaction data according to the first transaction data. If the third transaction data decrypted by each second node device is the same as the first transaction data, the third transaction data is verified. Regardless of whether the second node device verifies the third transaction data or fails, a verification result on the third transaction data is obtained, and the verification result indicates that the second node device verifies the third transaction data or fails, that is, the verification result can be a verification pass or a verification failure.
[0072] S404: The first node device receives the verification result and the third transaction data sent by each second node device.
[0073] After each second node device completes verification of the third transaction data and generates a verification result, the verification result and the third transaction data are sent to the first node device, so the first node device receives the verification result and the third transaction data sent by each second node device. Regardless of whether the second node device passes or fails to verify the third verification data, the verification result and the third transaction data are sent to the first node device, so that the first node device reaches a consensus on the third transaction data based on the verification result.
[0074] In one implementation, the second node device sends the verification result and the third transaction data to the first node device only after the verification of the third transaction data is passed, that is, the verification results received by the first node device are all verification results that have passed the verification. Optionally, the second node device sends the verification result to the first node device only when the verification of the third transaction data fails, that is, the verification results received by the first node device are all verification results that have failed the verification. This method allows the first node device to directly determine whether the third transaction data has passed the consensus based on the number of verification results received in the future.
[0075] In one implementation, each second node device sends the verification result and the third transaction data to all node devices except the node device itself, so that each node device can reach a consensus on the third transaction data based on the verification result. This method enables each node device to determine whether to execute a transaction based on the third transaction data based on the consensus result of the node device itself on the third transaction data.
[0076] Exemplarily, the first node device is node device A, and the second node device includes node device B, node device C and node device D. When node device B, node device C and node device D complete the verification of the third verification data, node device B sends the verification result B for the third transaction data and the third transaction data to node device A, node device C and node device D, node device C sends the verification result C for the third transaction data and the third transaction data to node device A, node device B and node device D, and node device D sends the verification result D for the third transaction data and the third transaction data to node device A, node device B and node device C. Therefore, except for the first node device, each second node device receives the verification result of the second node device except the node device itself, so that each node device can reach a consensus on the third transaction data based on the verification result, that is, the first node device can reach a consensus on the third transaction data based on the verification results and the third transaction data from each second node device, and each second node device can also reach a consensus on the third transaction data based on the second node devices except the node device itself and the third transaction data.
[0077] S405: The first node device reaches a consensus on the third transaction data according to various verification results.
[0078] Specifically, the first node device reaches a consensus on the third transaction data according to the number of verification results that pass the verification or the number of verification results that fail the verification.
[0079] In one implementation, the first node device determines the number of each verification result as a verification pass; if the number of verification passes is greater than a first preset threshold, the first node device passes the consensus on the third transaction data, and the first preset threshold is pre-set by each node device in the blockchain network. The first preset threshold can be half of the total number of each node device in the blockchain network. Optionally, the first preset threshold can also be two-thirds of the total number of each node device in the blockchain network, and so on, which are not limited here. For example, the first preset threshold is half of the total number of each node device in the blockchain network, and the total number of node devices in the blockchain network is 127. The first node device determines that the number of verification results that pass the verification is 75 among all the verification results received. Among all the verification results, the number of verification results that pass the verification is greater than the first preset threshold, that is, greater than half of the total number of all node devices, and the first node device passes the consensus on the third transaction data.
[0080] In one implementation, the first node device determines that each verification result is the number of failed verifications; if the number of failed verifications is greater than a second preset threshold, the first node device fails to pass the consensus on the third transaction data. The second preset threshold is pre-set by each node device in the blockchain network. The second preset threshold can be one-third of the total number of each node device in the blockchain network. Optionally, the second preset threshold can also be two-thirds of the total number of each node device in the blockchain network, and so on. The second preset threshold and the first preset threshold can be the same or different, and are not limited here. For example, the second preset threshold is two-thirds of the total number of all node devices in the blockchain network, and the total number of all node devices is 218. The verification result determined by the first node device in the received verification result is 169. In all verification results, the number of verification results that fail to pass the verification is greater than the second preset threshold, that is, greater than two-thirds of the total number of all node devices, and the first node device fails to pass the consensus on the third transaction data.
[0081] In one implementation, the first node device determines the number of verification results that are passed and the number of verification results that are not passed; if the number of verification results that are passed is greater than the number of verification results that are not passed, the first node device passes the consensus on the third transaction data. For example, the first node device receives a total of 261 verification results, and the number of verification results determined to be passed in all the verification results is 184, and the number of verification results determined to be not passed is 77. The number of verification results determined to be passed is greater than the number of verification results that are not passed, and the first node device passes the consensus on the third transaction data.
[0082] In one implementation, if the second node device sends the verification result and the third transaction data to the first node device only when the third transaction data is verified to be successful, then when the number of verification results received is greater than a first preset threshold, the first node device reaches a consensus on the third transaction data, and the first preset threshold is as described above and will not be repeated; or if the second node device sends the verification result and the third transaction data to the first node device only when the third transaction data is verified to be unsuccessful, then when the number of verification results received is greater than a second preset threshold, the first node device fails to reach a consensus on the third transaction data, and the second preset threshold is as described above and will not be repeated.
[0083] In one implementation, each second node device sends the verification result of the node device and the third transaction data to each second node device other than the node device itself. Each second node device may also reach a consensus on the third transaction data based on the received verification result. The consensus method of each second node device on the third transaction data is the same as that of the first node device, which will not be repeated here.
[0084] S406: If the consensus on the third transaction data is passed, the first node device executes the transaction according to the third transaction data.
[0085] If the first node device reaches consensus on the third transaction data, it means that the third transaction data is reliable transaction data, that is, after the first transaction data is encrypted and decrypted, the third transaction data obtained is reliable data and has not been tampered with by malicious nodes, etc. Then, the first node device can execute transactions based on the third transaction data. The transaction executed by the first node device can be chain processing of the third transaction data, or conversion algorithm processing of the third transaction data to obtain other transaction data, and so on.
[0086] In one implementation, when any second node device among the second node devices reaches a consensus on the third transaction data, if any second node device passes the consensus on the third transaction data, the second node device may execute the transaction according to the third transaction data.
[0087] In the embodiment of the present application, the first node device sends the first transaction data and the first ciphertext to each second node device. After each second node device decrypts the first ciphertext to obtain the third transaction data, it verifies the third transaction data according to the first transaction data and obtains the verification result. The first node device reaches a consensus on the third transaction data according to each verification result and the third transaction data from the second node device. If the consensus on the third transaction data is passed, the first node device executes the transaction according to the third transaction data. The first node device executes the transaction according to the third transaction data only after the consensus on the third transaction data is passed, which can improve the reliability of the transaction.
[0088] See also Figure 5 , Figure 5 It is a structural diagram of a node device provided by an embodiment of the present invention. The node device can be applied in a first node device. The node device 50 includes a processor 501, a memory 502, and a communication interface 503. The processor 501, the memory 502, and the communication interface 503 are connected via one or more communication buses.
[0089] The processor 501 is configured to support the first node device to execute Figure 2 , Figure 3 and Figure 4 The corresponding functions of the first node device in the illustrated embodiment. The processor 501 may be a central processing unit (CPU), a network processor (NP), a hardware chip or any combination thereof.
[0090] The memory 502 is used to store program codes, etc. The memory 502 may include a volatile memory, such as a random access memory (RAM); the memory 502 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 502 may also include a combination of the above-mentioned types of memory.
[0091] The communication interface 503 is used to receive and send data. For example, the communication interface 503 is used to send the first transaction data and the first ciphertext to each second node device in the blockchain network, or the communication interface 503 is used to receive the verification result and the third transaction data sent by each second node device.
[0092] In the embodiment of the present invention, the first node device 50 includes a plurality of communication interfaces, wherein the communication interface for sending data and the communication interface for receiving data may not be the same communication interface.
[0093] The processor 501 may call the program code stored in the memory 502 to perform the following operations:
[0094] When the processor 501 is running the smart contract, if a first encryption event is triggered, the middleware is called, and the first encryption event indicates that the first transaction data is encrypted, and the middleware includes an encryption algorithm library;
[0095] The processor 501 searches the middleware for an encryption algorithm library corresponding to the first encryption event;
[0096] The processor 501 calls the encryption algorithm library to encrypt the first transaction data to obtain a first ciphertext.
[0097] In one implementation, the middleware includes at least one configuration file, and the at least one configuration file includes a configuration file for a symmetric encryption algorithm, a configuration file for an asymmetric encryption algorithm, or a configuration file for a hash algorithm. The processor 501 receives update information of a target encryption algorithm, and the target encryption algorithm is a symmetric encryption algorithm, an asymmetric encryption algorithm, or a hash algorithm; the processor 501 determines a target configuration file corresponding to the target encryption algorithm in at least one configuration file; the processor 501 updates a target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file to obtain an updated target encryption algorithm library.
[0098] In one implementation, the processor 501 updates the target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file, and after obtaining the updated target encryption algorithm library, the following operations may be performed:
[0099] When the processor 501 is running a smart contract, if a second encryption event is triggered, the middleware is called, and the second encryption event indicates that the second transaction data is to be encrypted; the processor 501 searches the middleware for an updated target encryption algorithm library corresponding to the second encryption event; the processor 501 calls the updated target encryption algorithm library to encrypt the second transaction data to obtain a second ciphertext.
[0100] In one implementation, the processor 501 calls the encryption algorithm library to encrypt the first transaction data, and after obtaining the first ciphertext, the following operations may be performed:
[0101] The processor 501 sends the first transaction data and the first ciphertext to each second node device in the blockchain network, so that each second node device verifies the third transaction data according to the first transaction data after decrypting the first ciphertext to obtain the third transaction data, and obtains a verification result. The second node device is a node device other than the first node device in the blockchain network; the processor 501 receives the verification result and the third transaction data sent by each second node device; the processor 501 reaches a consensus on the third transaction data according to each verification result; if the processor 501 passes the consensus on the third transaction data, the transaction is executed according to the third transaction data.
[0102] In one implementation, the processor 501 reaches a consensus on the third transaction data according to each verification result, and specifically performs the following operations:
[0103] The processor 501 determines each verification result as the number of verification passes; if the number of verification passes is greater than the first preset threshold, the processor 501 passes the consensus on the third transaction data.
[0104] In one implementation, the processor 501 reaches a consensus on the third transaction data according to each verification result, and specifically performs the following operations:
[0105] The processor 501 determines that each verification result is the number of verification failures; if the number of verification failures is greater than a second preset threshold, the processor 501 fails the third transaction data consensus.
[0106] In one implementation, the processor 501 reaches a consensus on the third transaction data according to each verification result, and specifically performs the following operations:
[0107] The processor 501 determines the number of verification results that pass the verification and the number of verification results that fail the verification; if the number of verification passes is greater than the number of verification fails, the processor 501 passes the consensus on the third transaction data.
[0108] See also Figure 6 , Figure 6 : is a structural diagram of a data encryption device provided by an embodiment of the present invention. The data encryption device may be arranged in a first node device. The data encryption device 60 may include:
[0109] A calling unit 601 is used to call the middleware if a first encryption event is triggered during the execution of the smart contract, the first encryption event indicates that the first transaction data is to be encrypted, and the middleware includes an encryption algorithm library;
[0110] A search unit 602, configured to search the middleware for an encryption algorithm library corresponding to the first encryption event;
[0111] The calling unit 601 is used to call the encryption algorithm library to encrypt the first transaction data to obtain the first ciphertext.
[0112] In one implementation, the middleware includes at least one configuration file, the at least one configuration file includes a configuration file of a symmetric encryption algorithm, a configuration file of an asymmetric encryption algorithm, or a configuration file of a hash algorithm, and the data encryption device further includes:
[0113] The communication unit 603 is used to receive update information of a target encryption algorithm, where the target encryption algorithm is a symmetric encryption algorithm, an asymmetric encryption algorithm, or a hash algorithm;
[0114] The search unit 602 is further configured to determine a target configuration file corresponding to the target encryption algorithm in at least one configuration file;
[0115] The updating unit 604 is used to update the target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file to obtain an updated target encryption algorithm library.
[0116] In one implementation, the update unit 604 updates the target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file. After obtaining the updated target encryption algorithm library, the calling unit 601 is also used to call the middleware if a second encryption event is triggered, and the second encryption event indicates that the second transaction data is to be encrypted; the search unit 602 is also used to search the middleware for the updated target encryption algorithm library corresponding to the second encryption event; the calling unit 601 is also used to call the updated target encryption algorithm library to encrypt the second transaction data to obtain a second ciphertext.
[0117] In one implementation, the calling unit 601 calls the encryption algorithm library to encrypt the first transaction data. After obtaining the first ciphertext, the communication unit 603 is also used to send the first transaction data and the first ciphertext to each second node device in the blockchain network, so that after each second node device decrypts the first ciphertext to obtain the third transaction data, it verifies the third transaction data according to the first transaction data to obtain a verification result. The second node device is a node device other than the first node device in the blockchain network; the communication unit 603 is also used to receive the verification result and the third transaction data sent by each second node device; the consensus unit 605 is used to reach a consensus on the third transaction data according to each verification result; the execution unit 606 is used to execute the transaction according to the third transaction data if the consensus on the third transaction data is passed.
[0118] In one implementation, the determination unit 606 is used to determine the number of verification passes for each verification result; the consensus unit 605 is also used to pass the consensus on the third transaction data if the number of verification passes is greater than a first preset threshold.
[0119] In one implementation, the determination unit 606 is used to determine the number of verification failures for each verification result; the consensus unit 605 is also used to determine that the third transaction data consensus fails if the number of verification failures is greater than a second preset threshold.
[0120] In one implementation, the determination unit 606 is used to determine the number of verification results that pass the verification and the number of verification results that fail the verification; the consensus unit 605 is also used to pass the consensus on the third transaction data if the number of verification passes is greater than the number of verification fails.
[0121] The specific implementation of each unit included in the above-mentioned data encryption device proposed in the embodiment of the present invention can refer to the description of the relevant contents in the above-mentioned embodiments, which will not be repeated here, and, Figure 6 The various modules in the data encryption device shown can be separately or completely combined into one or several other modules to form, or one (some) of the modules can be further divided into multiple smaller modules in function to form, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above modules are divided based on logical functions. In practical applications, the functions of one module can also be realized by multiple modules, or the functions of multiple modules can be realized by one module. In other embodiments of the present application, other modules may also be included. In practical applications, these functions can also be implemented with the assistance of other modules, and can be implemented by the collaboration of multiple modules, which is not limited by the present application.
[0122] The embodiment of the present invention also provides a computer-readable storage medium that can be used to store Figure 2 , Figure 3 as well as Figure 4 The computer software instructions used by the first node device in the illustrated embodiment include instructions for executing the program designed for the first node device in the above-mentioned embodiment.
[0123] The computer-readable storage medium includes but is not limited to a flash memory, a hard disk, and a solid-state drive.
[0124] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A data encryption method, It is characterized in that The method is applied to a first node device, comprising: During the running of the smart contract, if a first encryption event is triggered, the middleware is called, the first encryption event indicates to encrypt the first transaction data, the middleware includes different types of encryption algorithm libraries and at least one configuration file, and different configuration files correspond to encryption algorithms in different types of encryption algorithm libraries; According to the encryption algorithm type corresponding to the first transaction data in the first encryption event, searching the middleware for an encryption algorithm library corresponding to the first encryption event; Calling the encryption algorithm library to encrypt the first transaction data to obtain a first ciphertext; Receive update information of the target encryption algorithm; Determining a target configuration file corresponding to the target encryption algorithm in the at least one configuration file; The target encryption algorithm library corresponding to the target encryption algorithm is updated based on the update information through the target configuration file to obtain an updated target encryption algorithm.
2. The method according to claim 1, It is characterized in that The at least one configuration file includes a configuration file of a symmetric encryption algorithm, a configuration file of an asymmetric encryption algorithm, or a configuration file of a hash algorithm, and the target encryption algorithm is a symmetric encryption algorithm, an asymmetric encryption algorithm, or a hash algorithm.
3. The method according to claim 2, It is characterized in that After the target encryption algorithm library corresponding to the target encryption algorithm is updated based on the update information through the target configuration file to obtain the updated target encryption algorithm library, the method further includes: During the execution of the smart contract, if a second encryption event is triggered, the middleware is called, and the second encryption event indicates that the second transaction data is to be encrypted; Searching the middleware for the updated target encryption algorithm library corresponding to the second encryption event; The updated target encryption algorithm library is called to encrypt the second transaction data to obtain a second ciphertext.
4. The method according to any one of claims 1 to 3, It is characterized in that The calling of the encryption algorithm library to encrypt the first transaction data to obtain the first ciphertext further includes: Sending the first transaction data and the first ciphertext to each second node device in the blockchain network, so that each second node device decrypts the first ciphertext to obtain the third transaction data and then verifies the third transaction data according to the first transaction data to obtain a verification result, wherein the second node device is a node device other than the first node device in the blockchain network; Receiving the verification results and the third transaction data sent by each of the second node devices; Reaching consensus on the third transaction data according to each verification result; If the consensus on the third transaction data is passed, the transaction is executed according to the third transaction data.
5. The method according to claim 4, It is characterized in that The reaching a consensus on the third transaction data according to the respective verification results includes: Determine the number of each verification result as a verification pass; If the number of passed verifications is greater than a first preset threshold, the third transaction data consensus is passed.
6. The method according to claim 4, It is characterized in that The reaching a consensus on the third transaction data according to the respective verification results includes: Determine the number of each verification result as a verification failure; If the number of failed checks is greater than a second preset threshold, the third transaction data consensus fails.
7. The method according to claim 4, It is characterized in that The reaching a consensus on the third transaction data according to the respective verification results includes: Determine the number of each verification result that passes the verification and the number of each verification result that fails the verification; If the number of verifications that pass is greater than the number of verifications that fail, the third transaction data consensus is passed.
8. A node device, It is characterized in that The method comprises a processor and a memory, wherein the processor and the memory are connected, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 7.
9. A data encryption device, It is characterized in that The device comprises: A calling unit, configured to call the middleware if a first encryption event is triggered during the running of the smart contract, wherein the first encryption event indicates that the first transaction data is to be encrypted, and the middleware includes different types of encryption algorithm libraries and at least one configuration file, wherein different configuration files correspond to encryption algorithms in different types of encryption algorithm libraries; a searching unit, configured to search the middleware for an encryption algorithm library corresponding to the first encryption event according to a type of encryption algorithm corresponding to the first transaction data in the first encryption event; A calling unit, configured to call the encryption algorithm library to encrypt the first transaction data to obtain a first ciphertext; A communication unit, used for receiving update information of a target encryption algorithm; The search unit is further configured to determine a target configuration file corresponding to the target encryption algorithm in the at least one configuration file; An updating unit is used to update a target encryption algorithm library corresponding to the target encryption algorithm based on the update information through the target configuration file to obtain an updated target encryption algorithm.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Cryptographic applications for a blockchain system
CN109313685A
Block chain consensus method and device and readable storage medium
CN109995536A
