Database data encryption method and terminal
By using the target encryption mapping table to encrypt and query database data, a highly unique ciphertext is generated, which solves the problems of high resource consumption and low query efficiency in the existing technology and realizes efficient encrypted data query.
Patent Information
- Application Number
- CN202111367743.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-18
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2041-11-18
AI Technical Summary
The existing technology consumes a lot of resources when encrypting data in the database and has low query efficiency, making it impossible to efficiently search the encrypted data.
The target encryption mapping table is used to encrypt the data to be encrypted, generate the initial ciphertext, and add the random number to the preset position to form the final ciphertext, which is saved to the database. When querying, the ciphertext set is queried instead of decrypting all the data, and the target encryption mapping table is used for decryption.
It reduces resource consumption, improves the query efficiency of encrypted data, ensures the uniqueness and security of ciphertext, and reduces the need to decrypt all data in the database.
Smart Images

Figure CN114218582B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data security technology, and in particular to a database data encryption method and terminal. Background Art
[0002] With the development of online information, the internet has impacted every aspect of our lives, and with it, the need for data security has become increasingly stringent. Sensitive data in databases must be encrypted to ensure data security. Data encryption is a core technology for data security, protecting it from theft, tampering, or destruction. However, users often face the challenge of searching within ciphertext.
[0003] In the prior art, data in a database is generally encrypted using AES (Advanced Encryption Standard) symmetric encryption. When searching encrypted data, two methods are usually used: one is to input the plaintext and key, decrypt it using the key and the database's own decryption method, and then perform a fuzzy query on the plaintext. This method relies on the database having a corresponding decryption method for the encryption algorithm. Each search requires all data to be decrypted before the search is performed; the other method is to read all the encrypted data from the database into memory, decrypt it all, and then perform a fuzzy query based on the plaintext after decryption. Both of the above methods have the disadvantages of consuming a large amount of resources and having long waiting times. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a database data encryption method and terminal, which can improve the query efficiency of encrypted data while reducing resource consumption.
[0005] In order to solve the above technical problems, a technical solution adopted by the present invention is:
[0006] A method for encrypting data in a database, comprising:
[0007] Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext;
[0008] Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database;
[0009] Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set;
[0010] The database is queried based on the ciphertext set to obtain target ciphertext, and the target ciphertext is decrypted according to the target encryption mapping table to obtain target data corresponding to the data to be queried.
[0011] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0012] A database data encryption terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:
[0013] Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext;
[0014] Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database;
[0015] Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set;
[0016] The database is queried based on the ciphertext set to obtain target ciphertext, and the target ciphertext is decrypted according to the target encryption mapping table to obtain target data corresponding to the data to be queried.
[0017] The beneficial effects of the present invention are as follows: when encrypting data, instead of using AES symmetric encryption as in the prior art, the data to be encrypted is encrypted based on a target encryption mapping table to obtain an initial ciphertext, a random number is added to a preset position of the initial ciphertext to obtain a final ciphertext, and the final ciphertext is saved in a database, thereby completing data encryption. Encryption is performed according to the encryption mapping table, and random numbers are added to a preset position of the initial ciphertext, which is conducive to ensuring the uniqueness of the ciphertext and facilitating subsequent data queries. When querying data, there is no need to decrypt and search all encrypted data in the database, but to encrypt the data to be queried to obtain a ciphertext set, and query the database based on the ciphertext set to obtain a target ciphertext, thereby changing the decryption of all data in the database of the prior art to encryption of the data to be queried, thereby reducing resource consumption while improving the query efficiency of encrypted data. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a flowchart of a method for encrypting database data according to an embodiment of the present invention;
[0019] Figure 2 This is a schematic diagram of the structure of a method for encrypting data in a database according to an embodiment of the present invention;
[0020] Figure 3 Schematic diagram of the data encryption process in the data encryption method of the database according to an embodiment of the present invention;
[0021] Figure 4 Schematic diagram of a data query process in a data encryption method for a database according to an embodiment of the present invention;
[0022] Figure 5 This is a schematic diagram of the encryption mapping in the data encryption method of the database according to the embodiment of the present invention;
[0023] Figure 6 This is a schematic diagram of the target encryption mapping in the database data encryption method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] To illustrate the technical content, achieved objectives and effects of the present invention in detail, the following description is given in conjunction with the embodiments and accompanying drawings.
[0025] Please refer to Figure 1 , an embodiment of the present invention provides a database data encryption method, comprising:
[0026] Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext;
[0027] Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database;
[0028] Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set;
[0029] The database is queried based on the ciphertext set to obtain target ciphertext, and the target ciphertext is decrypted according to the target encryption mapping table to obtain target data corresponding to the data to be queried.
[0030] From the above description, it can be seen that the beneficial effect of the present invention is that: when encrypting data, it is no longer like the prior art that uses AES symmetric encryption, but instead encrypts the data to be encrypted based on the target encryption mapping table to obtain the initial ciphertext, adds the random number to the preset position of the initial ciphertext to obtain the final ciphertext, and saves it to the database to complete the data encryption. Encryption according to the encryption mapping table and adding the random number to the preset position of the initial ciphertext are conducive to ensuring the uniqueness of the ciphertext and facilitating subsequent data queries. When querying data, there is no need to decrypt and search all encrypted data in the database, but to encrypt the data to be queried to obtain a ciphertext set, and query the database based on the ciphertext set to obtain the target ciphertext, changing the decryption of all data in the database of the prior art to encrypting the data to be queried, thereby reducing resource consumption while improving the query efficiency of encrypted data.
[0031] Furthermore, before obtaining the random number and the target encryption mapping table according to the received encryption request of the data to be encrypted, the method further includes:
[0032] Determine a preset number of encryption mapping tables;
[0033] The step of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted comprises:
[0034] Obtaining a random number from a preset range according to a received encryption request of the data to be encrypted;
[0035] Taking the preset number as a modulus, taking the remainder of the modulus for the random number;
[0036] A target encryption mapping table is determined from the preset number of encryption mapping tables according to the remainder.
[0037] As can be seen from the above description, a target encryption mapping table is randomly determined from a certain number of pre-set encryption mapping tables, and data is subsequently encrypted using the randomly determined target encryption mapping table, thereby improving the security of data encryption.
[0038] Furthermore, encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext includes:
[0039] Obtaining a corresponding value to be encrypted from the data to be encrypted according to a binary code comparison table;
[0040] Mapping the value to be encrypted according to the target encryption mapping table to obtain a mapping value;
[0041] Converting the mapping value into a first preset base number to obtain an initial ciphertext;
[0042] Adding the random number to a preset position of the initial ciphertext to obtain the final ciphertext includes:
[0043] The random number is converted into the first preset base number and added to the preset position of the initial ciphertext to obtain the final ciphertext.
[0044] As can be seen from the above description, when encryption is performed, the data to be encrypted is first converted into a numerical value to be encrypted, then the numerical value to be encrypted is mapped according to the target encryption mapping table, and then the mapped value is converted into a first preset base number to obtain an initial ciphertext, and finally the random number is converted into a first preset base number and added to the preset position of the initial ciphertext to obtain the final ciphertext, which increases the complexity of the final ciphertext and thereby improves the security and reliability of the encryption.
[0045] Furthermore, encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set includes:
[0046] Encrypting the data to be queried one by one using the preset number of encryption mapping tables according to the received query request of the data to be queried to obtain a ciphertext set;
[0047] The querying the database based on the ciphertext set to obtain the target ciphertext includes:
[0048] Obtaining the final ciphertext in the database, and removing the ciphertext at the preset position of the final ciphertext to obtain the initial ciphertext;
[0049] Traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed, and matching the traversed target ciphertext to be queried with the initial ciphertext;
[0050] During the matching, determining whether the target ciphertext to be queried is included in the initial ciphertext; if not, returning to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed; if so, determining the target encryption mapping table corresponding to the initial ciphertext based on the ciphertext at the preset position;
[0051] Determine whether the target encryption map is consistent with the encryption map corresponding to the target ciphertext to be queried; if so, determine the final ciphertext as the target ciphertext; if not, return to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed.
[0052] As can be seen from the above description, when data needs to be queried, not all encrypted data in the database are decrypted. Instead, all encryption mapping tables are used to encrypt the data to be queried one by one to obtain a series of ciphertext sets. The ciphertext at the preset position of the final ciphertext in the database is removed to obtain the initial ciphertext. The initial ciphertext is first matched one by one with the ciphertext to be queried in the ciphertext set. When the initial ciphertext includes the target ciphertext to be queried, it is determined based on the ciphertext at the preset position whether the initial ciphertext and the ciphertext to be queried use the same encryption mapping table. If so, it can be determined as the target ciphertext and then decrypted, thereby realizing fuzzy query of database data. Since there is no need to decrypt all data in the database, the security of the database data is further improved.
[0053] Furthermore, decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried includes:
[0054] removing the ciphertext at the preset position of the target ciphertext to obtain a target initial ciphertext, and converting the target initial ciphertext into a second preset base number to obtain a converted target initial ciphertext;
[0055] Performing reverse mapping on the converted target initial ciphertext according to the target encryption mapping table to obtain a reverse mapping value;
[0056] The target data corresponding to the data to be queried is obtained based on the binary code comparison table and the reverse mapping value.
[0057] As can be seen from the above description, when decrypting the target ciphertext, the ciphertext at the preset position of the target ciphertext is removed, and the obtained target initial ciphertext is converted into a second preset base number to obtain the converted target initial ciphertext. The converted target initial ciphertext is reverse mapped according to the target encryption mapping table to obtain a reverse mapping value. Finally, based on the binary code comparison table and the reverse mapping value, the target data corresponding to the data to be queried is obtained, thereby realizing the decryption of the ciphertext in the database.
[0058] Please refer to Figure 2 Another embodiment of the present invention provides a database data encryption terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0059] Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext;
[0060] Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database;
[0061] Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set;
[0062] The database is queried based on the ciphertext set to obtain target ciphertext, and the target ciphertext is decrypted according to the target encryption mapping table to obtain target data corresponding to the data to be queried.
[0063] From the above description, it can be seen that the beneficial effect of the present invention is that: when encrypting data, it is no longer like the prior art that uses AES symmetric encryption, but instead encrypts the data to be encrypted based on the target encryption mapping table to obtain the initial ciphertext, adds the random number to the preset position of the initial ciphertext to obtain the final ciphertext, and saves it to the database to complete the data encryption. Encryption according to the encryption mapping table and adding the random number to the preset position of the initial ciphertext are conducive to ensuring the uniqueness of the ciphertext and facilitating subsequent data queries. When querying data, there is no need to decrypt and search all encrypted data in the database, but to encrypt the data to be queried to obtain a ciphertext set, and query the database based on the ciphertext set to obtain the target ciphertext, changing the decryption of all data in the database of the prior art to encrypting the data to be queried, thereby reducing resource consumption while improving the query efficiency of encrypted data.
[0064] Furthermore, before obtaining the random number and the target encryption mapping table according to the received encryption request of the data to be encrypted, the method further includes:
[0065] Determine a preset number of encryption mapping tables;
[0066] The step of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted comprises:
[0067] Obtaining a random number from a preset range according to a received encryption request of the data to be encrypted;
[0068] Taking the preset number as a modulus, taking the remainder of the modulus for the random number;
[0069] A target encryption mapping table is determined from the preset number of encryption mapping tables according to the remainder.
[0070] As can be seen from the above description, a target encryption mapping table is randomly determined from a certain number of pre-set encryption mapping tables, and data is subsequently encrypted using the randomly determined target encryption mapping table, thereby improving the security of data encryption.
[0071] Furthermore, encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext includes:
[0072] Obtaining a corresponding value to be encrypted from the data to be encrypted according to a binary code comparison table;
[0073] Mapping the value to be encrypted according to the target encryption mapping table to obtain a mapping value;
[0074] Converting the mapping value into a first preset base number to obtain an initial ciphertext;
[0075] Adding the random number to a preset position of the initial ciphertext to obtain the final ciphertext includes:
[0076] The random number is converted into the first preset base number and added to the preset position of the initial ciphertext to obtain the final ciphertext.
[0077] As can be seen from the above description, when encryption is performed, the data to be encrypted is first converted into a numerical value to be encrypted, then the numerical value to be encrypted is mapped according to the target encryption mapping table, and then the mapped value is converted into a first preset base number to obtain an initial ciphertext, and finally the random number is converted into a first preset base number and added to the preset position of the initial ciphertext to obtain the final ciphertext, which increases the complexity of the final ciphertext and thereby improves the security and reliability of the encryption.
[0078] Furthermore, encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set includes:
[0079] Encrypting the data to be queried one by one using the preset number of encryption mapping tables according to the received query request of the data to be queried to obtain a ciphertext set;
[0080] The querying the database based on the ciphertext set to obtain the target ciphertext includes:
[0081] Obtaining the final ciphertext in the database, and removing the ciphertext at the preset position of the final ciphertext to obtain the initial ciphertext;
[0082] Traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed, and matching the traversed target ciphertext to be queried with the initial ciphertext;
[0083] During the matching, determining whether the target ciphertext to be queried is included in the initial ciphertext; if not, returning to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed; if so, determining the target encryption mapping table corresponding to the initial ciphertext based on the ciphertext at the preset position;
[0084] Determine whether the target encryption map is consistent with the encryption map corresponding to the target ciphertext to be queried; if so, determine the final ciphertext as the target ciphertext; if not, return to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed.
[0085] As can be seen from the above description, when data needs to be queried, not all encrypted data in the database are decrypted. Instead, all encryption mapping tables are used to encrypt the data to be queried one by one to obtain a series of ciphertext sets. The ciphertext at the preset position of the final ciphertext in the database is removed to obtain the initial ciphertext. The initial ciphertext is first matched one by one with the ciphertext to be queried in the ciphertext set. When the initial ciphertext includes the target ciphertext to be queried, it is determined based on the ciphertext at the preset position whether the initial ciphertext and the ciphertext to be queried use the same encryption mapping table. If so, it can be determined as the target ciphertext and then decrypted, thereby realizing fuzzy query of database data. Since there is no need to decrypt all data in the database, the security of the database data is further improved.
[0086] Furthermore, decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried includes:
[0087] removing the ciphertext at the preset position of the target ciphertext to obtain a target initial ciphertext, and converting the target initial ciphertext into a second preset base number to obtain a converted target initial ciphertext;
[0088] Performing reverse mapping on the converted target initial ciphertext according to the target encryption mapping table to obtain a reverse mapping value;
[0089] The target data corresponding to the data to be queried is obtained based on the binary code comparison table and the reverse mapping value.
[0090] As can be seen from the above description, when decrypting the target ciphertext, the ciphertext at the preset position of the target ciphertext is removed, and the obtained target initial ciphertext is converted into a second preset base number to obtain the converted target initial ciphertext. The converted target initial ciphertext is reverse mapped according to the target encryption mapping table to obtain a reverse mapping value. Finally, based on the binary code comparison table and the reverse mapping value, the target data corresponding to the data to be queried is obtained, thereby realizing the decryption of the ciphertext in the database.
[0091] The above-mentioned database data encryption method and terminal of the present invention can be applied to any database that needs to encrypt source data and store ciphertext. The following is an explanation through specific implementation methods:
[0092] Example 1
[0093] Please refer to Figure 1 , 3 , 5. A data encryption method for a database in this embodiment includes:
[0094] S0. Determine a preset number of encryption mapping tables;
[0095] Among them, the preset number can be set according to the actual situation. For example, the preset number is set according to the required security and search efficiency. The higher the security, the more encryption mapping tables; the higher the search efficiency, the fewer encryption mapping tables.
[0096] The encryption mapping table includes a first preset value and a second preset value corresponding to the first preset value;
[0097] In another optional implementation manner, assuming that data is stored in the GB2312-80 national standard code on a computer, the range of the first preset value is the encoding range in the GB2312-80 national standard code, and the range of the second preset value is taken as 1 to the total number of the first preset values. For example, if the first preset value in the encryption mapping table is 1601 and the second preset value is 0004, it means that the Chinese character '啊' is encrypted and represented by the number 0004.
[0098] In an optional implementation manner, assuming that data is stored in ASCII code on a computer, each byte contains 8-bit binary numbers; 8-bit binary numbers are decimal numbers 0-255. Therefore, the ranges of both the first preset value and the second preset value are 0-255; the encryption mapping table stores the mapping relationship between the first preset value and the second preset value. For example, if the first preset value in the encryption mapping table is 2 and the second preset value is 5, it means that the number 2 is encrypted and represented by the number 5.
[0099] Specifically, as Figure 3 , 5 shown, it further includes that after generating a preset number of encryption mapping tables, perform a duplicate removal process on the preset number of encryption mapping tables, that is, in the same encryption mapping table, the second preset values mapped by each first preset value are different, and for each pair of first preset value and second preset value in different encryption mapping tables are also different. For example, if there is an encryption mapping table that maps 0 to 1, then 0 in other encryption mapping tables cannot be mapped to 1, so as to ensure that the same plaintext data will not be encrypted into the same ciphertext through different encryption mapping tables during the encryption process.
[0100] As Figure 5 shown, Figure 5 the left column in it is the first preset value, and the right column is the second preset value; <00,same ciphertext through different encryption mapping tables during the encryption process.
[0100] As Figure 5 shown, Figure 5 the left column in it is the first preset value, and the right column is the second preset value;
[0101] S1. Obtaining a random number and a target encryption mapping table according to a received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext;
[0102] Specifically, such as Figure 3 As shown, the obtaining of a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted includes:
[0103] S11. Obtaining a random number from a preset range according to the received encryption request of the data to be encrypted;
[0104] Wherein, the preset range is 0-255;
[0105] S12, taking the preset number as a modulus, and obtaining the remainder of the modulus of the random number;
[0106] Specifically, the preset number of encryption maps is used as a modulus, and the remainder of the modulus is obtained for the random number;
[0107] S13, determining a target encryption map from the preset number of encryption maps according to the remainder;
[0108] Among them, each encryption map has a corresponding number, which is convenient for determining the target encryption map according to the remainder;
[0109] For example, if the preset number is 20 and the random number is 25, then the remainder of the modulus 20 of the random number 25 is 5, then the fifth encryption map from the 20 encryption maps is determined as the target encryption map;
[0110] S2. Add the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and save the final ciphertext to a database;
[0111] S3. Encrypt the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set;
[0112] S4. Query the database based on the ciphertext set to obtain target ciphertext, and decrypt the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried.
[0113] Example 2
[0114] Please refer to Figure 3 、 6 Based on the first embodiment, this embodiment further defines how to encrypt the encrypted data, specifically:
[0115] like Figure 3As shown, in S1, the data to be encrypted is encrypted based on the target encryption mapping table to obtain the initial ciphertext including:
[0116] S14, obtaining a corresponding value to be encrypted from the data to be encrypted according to a binary code comparison table;
[0117] S15, mapping the value to be encrypted according to the target encryption mapping table to obtain a mapping value;
[0118] S16. Convert the mapping value into a first preset base number to obtain an initial ciphertext;
[0119] In an optional embodiment, the first preset base number is a hexadecimal number, and the binary code comparison table is an ASCII code comparison table. Figure 5 As shown;
[0120] Specifically, assuming that the data to be encrypted is 52648, 52648 is converted into the corresponding encrypted value according to the binary encoding comparison table, that is, 53, 50, 54, 52, 56. Figure 6 The encryption mapping table shown is the determined target encryption mapping table, then 53 is mapped to 55, 50 is mapped to 76, 54 is mapped to 46, 52 is mapped to 120, and 56 is mapped to 18, obtaining the mapping values 55, 76, 46, 120, and 18. Convert the mapping values into hexadecimal numbers to obtain the initial ciphertext 374c2e7812.
[0121] In step S2, the random number is added to a preset position of the initial ciphertext to obtain the final ciphertext, which includes:
[0122] Converting the random number into a number in the first preset base and adding it to a preset position of the initial ciphertext to obtain a final ciphertext;
[0123] Wherein, the preset position is the end position of the initial ciphertext;
[0124] Specifically, assuming Figure 6 The random number corresponding to the target encrypted map shown is 25. The random number 25 is converted into a hexadecimal number, ie, 19, to obtain the final ciphertext 374c2e781219. The random number is used to determine which of the multiple encrypted maps is the target encrypted map during decryption.
[0125] Example 3
[0126] Please refer to Figure 4 、 6 Based on the first or second embodiment, this embodiment further defines how to query the query data, specifically:
[0127] like Figure 4As shown, the S3 is specifically:
[0128] Encrypting the data to be queried one by one using the preset number of encryption mapping tables according to the received query request of the data to be queried to obtain a ciphertext set;
[0129] Specifically, when performing a data query, each encryption map is used to encrypt the query data to obtain a series of ciphertexts, namely, a ciphertext set;
[0130] The encryption method is as described above and will not be described again here;
[0131] In S4, the database is queried based on the ciphertext set to obtain the target ciphertext, including:
[0132] S41, obtaining the final ciphertext in the database, and removing the ciphertext at the preset position of the final ciphertext to obtain the initial ciphertext;
[0133] Specifically, the final ciphertext in the database is obtained, and the last two ciphertexts of the final ciphertext are removed to obtain the initial ciphertext;
[0134] S42, traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed, and matching the traversed target ciphertext to be queried with the initial ciphertext;
[0135] S43, during the matching, determining whether the initial ciphertext includes the target ciphertext to be queried; if not, returning to execute S42; if so, determining the target encryption mapping table corresponding to the initial ciphertext based on the ciphertext at the preset position;
[0136] The initial ciphertext refers to the ciphertext after removing the preset position;
[0137] Specifically, obtaining a final ciphertext corresponding to the initial ciphertext, and obtaining a ciphertext at a preset position on the final ciphertext, that is, a random number, and determining a target encryption mapping table corresponding to the initial ciphertext according to the random number;
[0138] For example, if the ciphertext at the preset position is 19, the preset number is 20, and the ciphertext at the preset position is a hexadecimal number, then 19 is converted to decimal 25, which is a random number. The remainder of 20 of the random number 25 is 5, and it can be determined that the target encryption map corresponding to the initial ciphertext is the fifth encryption map;
[0139] S44, determining whether the target encryption map is consistent with the encryption map corresponding to the target ciphertext to be queried; if so, determining the final ciphertext as the target ciphertext; if not, returning to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed;
[0140] That is, in step S43, it has been determined that the initial ciphertext includes the target ciphertext to be queried. If the target encryption mapping table corresponding to the initial ciphertext and the encryption mapping table corresponding to the target ciphertext to be queried are the same, then the encryption methods of the two are also the same, and it can be determined that the content before encryption is also the same;
[0141] Decrypting the target ciphertext according to the target encryption mapping table in S4 to obtain target data corresponding to the data to be queried includes:
[0142] S45. Remove the ciphertext at the preset position of the target ciphertext to obtain a target initial ciphertext, and convert the target initial ciphertext into a second preset base number to obtain a converted target initial ciphertext;
[0143] The second preset base number is the same as the base number of the determined random number. For example, if the random number is a decimal number 25, the second preset base number is a decimal number.
[0144] Specifically, assuming the target ciphertext is 374c2e78124e, remove the last two ciphertexts to get the target initial ciphertext 374c2e7812, and convert the target initial ciphertext into a decimal number to get 55, 76, 46, 120, 18;
[0145] S46. Reverse mapping the converted target initial ciphertext according to the target encryption mapping table to obtain a reverse mapping value;
[0146] Specifically, according to Figure 6 The fifth encryption map shown reversely maps 55, 76, 46, 120, and 18 to obtain reverse mapping values of 53, 50, 54, 52, and 56.
[0147] S47, obtaining target data corresponding to the data to be queried based on the binary code comparison table and the reverse mapping value;
[0148] Specifically, based on the binary coding comparison table and the reverse mapping values 53, 50, 54, 52, and 56, the target data 52648 is obtained.
[0149] Example 4
[0150] Please refer to Figure 2A database data encryption terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, each step of the database data encryption method in the first, second, or third embodiment is implemented.
[0151] In summary, the present invention provides a database data encryption method and terminal, which obtains a random number and a target encryption mapping table according to an encryption request of the data to be encrypted, and encrypts the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext; adds the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saves the final ciphertext to the database; encrypts the data to be queried according to a query request of the data to be queried to obtain a ciphertext set; queries the database based on the ciphertext set to obtain a target ciphertext, and decrypts the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried. Specifically, when encrypting data, the data to be encrypted is obtained according to the binary code comparison table to obtain the corresponding ciphertext. Encrypted value; mapping the encrypted value according to the target encryption mapping table, converting the mapped value into a first preset base number to obtain an initial ciphertext, converting the random number into a first preset base number and adding it to a preset position of the initial ciphertext to obtain a final ciphertext, which increases the complexity of the final ciphertext, helps to ensure the uniqueness of the ciphertext, and facilitates subsequent data query, thereby improving the security and reliability of encryption; when querying data, there is no need to decrypt and search all encrypted data in the database, but instead uses a preset number of encryption mapping tables to encrypt the query data one by one to obtain a ciphertext set, and queries the database based on the ciphertext set to obtain a target ciphertext, changing from decrypting all data in the database in the prior art to encrypting the data to be queried, thereby reducing resource consumption while improving the query efficiency of encrypted data.
[0152] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's description and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for encrypting data in a database, characterized in that: include: Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext; Specifically include: Obtaining a corresponding value to be encrypted from the data to be encrypted according to a binary code comparison table; Mapping the value to be encrypted according to the target encryption mapping table to obtain a mapping value; Converting the mapping value into a first preset base number to obtain an initial ciphertext; Adding the random number to a preset position of the initial ciphertext to obtain the final ciphertext includes: Converting the random number into a number in the first preset base and adding it to a preset position of the initial ciphertext to obtain a final ciphertext; Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database; Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set; Querying the database based on the ciphertext set to obtain target ciphertext, and decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried; The method of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted includes: Determine a preset number of encryption mapping tables; Deduplication is performed on a preset number of encrypted maps; The step of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted comprises: Obtaining a random number from a preset range according to a received encryption request of the data to be encrypted; Taking the preset number as a modulus, taking the remainder of the modulus for the random number; A target encryption mapping table is determined from the preset number of encryption mapping tables according to the remainder.
2. The method for encrypting database data according to claim 1, wherein: The step of encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set includes: Encrypting the data to be queried one by one using the preset number of encryption mapping tables according to the received query request of the data to be queried to obtain a ciphertext set; The querying the database based on the ciphertext set to obtain the target ciphertext includes: Obtaining the final ciphertext in the database, and removing the ciphertext at the preset position of the final ciphertext to obtain the initial ciphertext; Traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed, and matching the traversed target ciphertext to be queried with the initial ciphertext; During the matching, determining whether the target ciphertext to be queried is included in the initial ciphertext; if not, returning to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed; if so, determining the target encryption mapping table corresponding to the initial ciphertext based on the ciphertext at the preset position; Determine whether the target encryption map is consistent with the encryption map corresponding to the target ciphertext to be queried; if so, determine the final ciphertext as the target ciphertext; if not, return to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed.
3. The method for encrypting database data according to claim 2, characterized in that: Decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried includes: removing the ciphertext at the preset position of the target ciphertext to obtain a target initial ciphertext, and converting the target initial ciphertext into a second preset base number to obtain a converted target initial ciphertext; Performing reverse mapping on the converted target initial ciphertext according to the target encryption mapping table to obtain a reverse mapping value; The target data corresponding to the data to be queried is obtained based on the binary code comparison table and the reverse mapping value.
4. A database data encryption terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: Obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted, and encrypting the data to be encrypted based on the target encryption mapping table to obtain an initial ciphertext; Specifically include: Obtaining a corresponding value to be encrypted from the data to be encrypted according to a binary code comparison table; Mapping the value to be encrypted according to the target encryption mapping table to obtain a mapping value; Converting the mapping value into a first preset base number to obtain an initial ciphertext; Adding the random number to a preset position of the initial ciphertext to obtain the final ciphertext includes: Converting the random number into a number in the first preset base and adding it to a preset position of the initial ciphertext to obtain a final ciphertext; Adding the random number to a preset position of the initial ciphertext to obtain a final ciphertext, and saving the final ciphertext to a database; Encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set; Querying the database based on the ciphertext set to obtain target ciphertext, and decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried; The method of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted includes: Determine a preset number of encryption mapping tables; Deduplication is performed on a preset number of encrypted maps; The step of obtaining a random number and a target encryption mapping table according to the received encryption request of the data to be encrypted comprises: Obtaining a random number from a preset range according to a received encryption request of the data to be encrypted; Taking the preset number as a modulus, taking the remainder of the modulus for the random number; A target encryption mapping table is determined from the preset number of encryption mapping tables according to the remainder.
5. A database data encryption terminal according to claim 4, characterized in that: The step of encrypting the data to be queried according to the received query request of the data to be queried to obtain a ciphertext set includes: Encrypting the data to be queried one by one using the preset number of encryption mapping tables according to the received query request of the data to be queried to obtain a ciphertext set; The querying the database based on the ciphertext set to obtain the target ciphertext includes: Obtaining the final ciphertext in the database, and removing the ciphertext at the preset position of the final ciphertext to obtain the initial ciphertext; Traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed, and matching the traversed target ciphertext to be queried with the initial ciphertext; During the matching, determining whether the target ciphertext to be queried is included in the initial ciphertext; if not, returning to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed; if so, determining the target encryption mapping table corresponding to the initial ciphertext based on the ciphertext at the preset position; Determine whether the target encryption map is consistent with the encryption map corresponding to the target ciphertext to be queried; if so, determine the final ciphertext as the target ciphertext; if not, return to the step of traversing each ciphertext to be queried in the ciphertext set until all ciphertexts to be queried in the ciphertext set have been traversed.
6. A database data encryption terminal according to claim 5, characterized in that: Decrypting the target ciphertext according to the target encryption mapping table to obtain target data corresponding to the data to be queried includes: removing the ciphertext at the preset position of the target ciphertext to obtain a target initial ciphertext, and converting the target initial ciphertext into a second preset base number to obtain a converted target initial ciphertext; Performing reverse mapping on the converted target initial ciphertext according to the target encryption mapping table to obtain a reverse mapping value; The target data corresponding to the data to be queried is obtained based on the binary code comparison table and the reverse mapping value.
Citation Information
Patent Citations
Information encrypting method
CN102904712A
Data query method and system, electronic device and storage medium
CN110347723A