Database management method, system and storage medium
By setting a hook function in the kernel of the database management system, it directly intercepts and processes the encryption and decryption operations of database files, solving the problem of database encryption performance loss in the existing technology, achieving fast and efficient ciphertext operations and improving data security. .
Patent Information
- Application Number
- CN202410516985.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-28
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-04-28
AI Technical Summary
Existing database encryption technologies such as Transparent Data Encryption (TDE) and trigger view technology often face performance loss problems in practical applications.
By setting hook functions in the kernel of the database management system, intercepting and intercepting system calls, encryption and decryption of database file data are implemented, and custom operation functions are directly called at the kernel level to perform ciphertext operations.
It effectively reduces the performance loss of database encryption, realizes fast and efficient ciphertext operations, and enhances data security. It also supports the requirements of the national secret algorithm, meets the compliance requirements of Class A security protection, and is used in production systems.
Smart Images

Figure CN118093555B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database management, and in particular to a database management method, system and storage medium. Background Art
[0002] With the rapid development of information technology, database encryption plays a vital role in protecting sensitive information from unauthorized access and leakage. Currently, the implementation of database encryption mostly relies on Transparent Data Encryption (TDE) technology or trigger view technology. However, the above TDE technology or trigger view technology often faces the problem of performance loss in practical applications. Summary of the invention
[0003] The main purpose of this application is to provide a database management method, system and storage medium, aiming to solve the problem of performance loss in current database encryption.
[0004] To achieve the above object, the present application provides a database management method, which is applied to a database management system and includes:
[0005] In response to an operation instruction on a database, a corresponding custom operation function is called through a hook function preset in the kernel of the database management system;
[0006] The target file in the database is encrypted using the custom operation function.
[0007] Optionally, when the target file is empty, the step of performing a ciphertext operation on the target file in the database by using the custom operation function includes:
[0008] Calling a preset random number generator module through a custom write operation function to generate a first key;
[0009] Obtaining unencrypted data to be written corresponding to the write operation instruction;
[0010] Encrypting the unencrypted data to be written in groups based on the first key to obtain encrypted data to be written, and writing the encrypted data to be written into the target file;
[0011] Encrypting the first key to obtain a second key;
[0012] Create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
[0013] Optionally, when the target file is not empty, the step of performing a ciphertext operation on the target file in the database by using the custom operation function includes:
[0014] Reading a second key in a metadata file corresponding to the target file through a custom write operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system;
[0015] Decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module;
[0016] Decrypting the encrypted data to be modified in the target file in groups based on the first key to obtain unencrypted data to be modified;
[0017] Obtaining unencrypted data to be written corresponding to the write operation instruction;
[0018] Combining the unencrypted data to be written with the unencrypted data to be modified to obtain unencrypted combined data;
[0019] The unencrypted combined data is encrypted in groups based on the first key to obtain encrypted combined data, and the encrypted combined data is written into the target file.
[0020] Optionally, the step of performing a ciphertext operation on a target file in the database by using the custom operation function includes:
[0021] Reading a second key in a metadata file corresponding to the target file through a custom read operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system;
[0022] Decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module;
[0023] The encrypted data to be read in the target file is decrypted in groups based on the first key to obtain unencrypted data to be read, wherein the encrypted data to be read is encrypted in groups based on the first key in advance.
[0024] Optionally, before the step of calling the corresponding custom operation function through a hook function preset in the kernel of the database management system in response to the operation instruction on the database, the method further includes:
[0025] Calling a preset random number generator module through a preset initialization function to generate a first key;
[0026] Encrypting the data of the unencrypted file stored in the database in groups based on the first key to obtain a corresponding temporary file;
[0027] Overwriting the unencrypted file with the temporary file to obtain the target file;
[0028] Encrypting the first key to obtain a second key;
[0029] Create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
[0030] Optionally, the method further comprises:
[0031] If the group encryption process corresponding to the target file generates padding data, the padding data is obtained and stored in the metadata file corresponding to the target file, wherein the padding data is used to perform group decryption on the data of the target file.
[0032] Optionally, in response to the operation instruction on the database, the step of calling the corresponding custom operation function through a hook function preset in the kernel of the database management system includes:
[0033] In response to an operation instruction on the database, intercepting a corresponding original operation function through the hook function;
[0034] If the original operation function meets the preset function type condition, and the target file meets the preset file type condition, the corresponding custom operation function is called through the hook function.
[0035] The present application also provides a database management system, which includes:
[0036] A calling module, used for responding to an operation instruction on a database and calling a corresponding custom operation function through a hook function preset in the kernel of the database management system;
[0037] The operation module is used to perform ciphertext operation on the target file in the database through the custom operation function.
[0038] Optionally, the database management system is communicatively connected to a switch, the switch is arranged in a data link between the client and the database, and the operation instruction is issued by the client.
[0039] The embodiment of the present application further provides a computer-readable storage medium, on which a database management program is stored. When the database management program is executed by a processor, the steps of the database management method described above are implemented.
[0040] The database management method, system and storage medium proposed in the embodiment of the present application, by responding to the operation instruction of the database, calling the corresponding custom operation function through the hook function preset in the kernel of the database management system; performing ciphertext operation on the target file in the database through the custom operation function. Based on the scheme of the present application, by directly setting the hook function in the kernel of the database management system, it is possible to respond quickly to the operation instruction of the database, and call the custom operation function to perform ciphertext operation on the target file in the database. Since the hook function is set at the kernel level, the ciphertext operation based on the custom operation function is faster and more efficient, which effectively reduces the performance loss of database encryption. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a flowchart of the first exemplary embodiment of the database management method of this application;
[0042] Figure 2 This is a schematic diagram of the encryption and decryption operation mechanism involved in the database management method of this application;
[0043] Figure 3 A schematic diagram of data writing involved in the database management method of this application;
[0044] Figure 4 This is a schematic diagram of a custom write operation function involved in the database management method of this application;
[0045] Figure 5 This is a schematic diagram of data modification involved in the database management method of this application;
[0046] Figure 6 This is a schematic diagram of data reading involved in the database management method of this application;
[0047] Figure 7 This is a schematic diagram of a custom read operation function involved in the database management method of this application;
[0048] Figure 8 This is a schematic diagram of the system initialization mechanism involved in the database management method of this application;
[0049] Fig. 9 This is a schematic diagram of the initialization function involved in the database management method of this application;
[0050] Fig.10 This is a first schematic diagram of a system deployment method involved in the database management method of this application;
[0051] Fig.11 This is the second schematic diagram of the system deployment method involved in the database management method of this application.
[0052] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0054] The main solution of the embodiment of the present application is: in response to the operation instruction of the database, the corresponding custom operation function is called through the hook function preset in the kernel of the database management system; the target file in the database is ciphered through the custom operation function. Based on the scheme of the present application, by directly setting the hook function in the kernel of the database management system, it is possible to respond quickly to the operation instruction of the database, and call the custom operation function to perform ciphered operation on the target file in the database. Since the hook function is set at the kernel level, the ciphered operation based on the custom operation function is faster and more efficient, which effectively reduces the performance loss of database encryption.
[0055] Reference Figure 1 The first embodiment of the database management method of the present application provides a flow chart, the method is applied to a database management system, the method includes:
[0056] Step S10, in response to the operation instruction for the database, the corresponding custom operation function is called through the hook function preset in the kernel of the database management system.
[0057] Specifically, with the rapid development of information technology, database encryption plays a vital role in protecting sensitive information from unauthorized access and leakage. Currently, the implementation of database encryption mostly relies on Transparent Data Encryption (TDE) technology or trigger view technology. However, the above TDE technology or trigger view technology often faces the problem of performance loss in practical applications.
[0058] To solve the above problems, this embodiment implements encryption and decryption of database file data by intercepting system calls in kernel mode for database service processes. The database management system involved in this embodiment is a software system independent of a specific database, which provides functions of creating, maintaining, managing and using databases.
[0059] First, preset hook functions in the kernel of the database management system, specifically, one or more specific call points are reserved in the underlying code (usually kernel-level code) of the database management system, which allow custom code or functions to be executed when a specific event occurs. Specifically, a hook function is a mechanism that allows developers to "hook" on a key execution path of the kernel of the database management system, that is, insert custom code logic. When a specific event occurs, such as an operation instruction for a database is received or executed, the kernel will check whether there is a hook function associated with the event. If so, the kernel will call these hook functions at the appropriate time to execute the custom logic defined by the developer. Based on the hook functions in the kernel of the database management system, it is possible to intercept and modify the read and write operations of the database file. By presetting hook functions in the kernel, developers can intercept access requests to database files and encrypt the data before it is written to the database, or decrypt the data before it is read from the database to the memory. In this way, it can be ensured that the data in the database can be stored and transmitted in an encrypted form even without modifying the database application or user operation habits, thereby enhancing data security.
[0060] Under the premise of setting up a hook function, the database management system responds to the operation instruction of the database and calls the corresponding custom operation function through the hook function. Among them, the operation instruction of the database refers to a specific command or request sent by the client to the database management system to perform a certain operation on the target file in the database. The custom operation function refers to the function corresponding to the operation instruction for performing ciphertext operation on the target file in the database. Specifically, the custom operation function corresponds to the original operation function one by one. For example, the function name of the original read operation function can be recorded as read, and its corresponding custom read operation function can be recorded as read'. In addition, the types of custom operation functions can also include: ① custom write operation function write' (corresponding to the original write operation function write): used to write data to a file or device; ② custom file pointer positioning function llseek' (corresponding to the original file pointer positioning function llseek): used to set the read and write position of the file (i.e. the position of the file pointer); ③ custom file link creation function link' (corresponding to the original file link creation function link): used to create a new link (hard link) pointing to an existing file; ④ custom file link deletion function unlink' (corresponding to the original file link deletion function unlink): used to delete a link to a file or directory (i.e. delete a file or directory); ⑤ custom file rename or move function rename' (corresponding to the original file rename or move function rename): used to rename or move a file or directory. It can be understood that more types of custom operation functions can be set according to actual needs, and they are not listed here one by one. When the hook function is not set, the operation instruction will trigger the execution of the corresponding original operation function, and when the hook function is set, the original operation function is intercepted through the hook function, and then the custom operation function corresponding to the original operation function is called.
[0061] Step S20: performing a ciphertext operation on the target file in the database through the custom operation function.
[0062] After calling the custom operation function corresponding to the original operation function through the hook function, the database management system will execute the custom operation function and perform ciphertext operations on the target file in the database through the custom operation function. Among them, the target file refers to the file corresponding to the operation instruction. If the target file is not empty, the data in the target file is encrypted in advance. The ciphertext operation here refers to the process of encrypting or decrypting the data of the target file in the database. Therefore, if the target file is read through the custom operation function, the read data needs to be decrypted after reading the data; if the target file is written through the custom operation function, the written data needs to be encrypted before writing the data. Similarly, various custom operation functions based on read / write involve encryption and decryption of data.
[0063] For example, through the custom write operation function write', the data is encrypted and then written into the database; through the custom file pointer positioning function llseek', the empty data is encrypted and then written into the database; through the custom read operation function which can be recorded as read', the data read out of the database is decrypted and then returned to the upper application; through the custom file link creation function link', the custom file link deletion function unlink', and the custom file renaming or moving function rename', the key file is copied, deleted and renamed.
[0064] In a possible implementation, after intercepting the original operation function, the hook function does not immediately call and execute the corresponding custom operation function, but determines whether encryption and decryption related processing is required by matching the file path name rules. Figure 2 For example, Figure 2This is a schematic diagram of the encryption and decryption operation mechanism involved in the database management method of this application. In the database service process of the database management system, in response to the operation instruction of calling the corresponding original operation function, the call to the original operation function is intercepted, and the type of the original operation function is determined. If it belongs to any of the original read operation function read, the original write operation function write, the original file pointer positioning function llseek, the original file link creation function link, the original file link deletion function unlink, and the original file rename or move function rename, then the corresponding custom operation function will be called. Then, it is determined whether the current database service process is a process that needs to be hooked (hook operation), and whether the target file is a file in the encryption configuration list. If the current database service process is not a process that needs to be hooked (hook operation), the original operation function is called; if the current database service process is a process that needs to be hooked (hook operation), and the target file is a file in the encryption configuration list, the corresponding custom operation function is further called, and the ciphertext operation is performed on the target file in the database through the custom operation function, specifically reading and writing the target file and the meta file (metadata file) corresponding to the target file.
[0065] Since this embodiment directly intercepts the system call to encrypt and decrypt the original binary data related to the target file, it does not need to search and associate the data, nor does it involve the submission of database transactions, etc. The performance is mainly reflected in the consumption of encryption and decryption compared to the original system call, so the overall performance will not be greatly affected by other factors.
[0066] More specifically, the encryption and decryption processing involved in this embodiment involves two keys.
[0067] For example, there are a first key and a second key for the target file, wherein the first key is used to encrypt the data of the target file and is randomly generated by the random number generator module of the database management system. The random number generator module can be constructed based on a true random number generator to ensure that the password cannot be guessed. The encryption algorithm corresponding to the first key can be a block encryption algorithm such as the SM4 encryption algorithm (national secret 4 encryption algorithm), the 3DES encryption algorithm (triple data encryption algorithm), and the AES encryption algorithm (advanced encryption standard). The block encryption algorithm is to divide the plaintext into groups of fixed length, and then encrypt each group independently. The second key is obtained by encrypting the first key by the database management system, and is stored in the metadata file corresponding to the target file (for example, recorded as "target file name.meta"), which is protected by the database management system and cannot be illegally copied. The encryption algorithm that can be used by the database management system to encrypt the first key is the SM2 encryption algorithm (national secret 2 encryption algorithm), the ECC encryption algorithm (elliptic encryption algorithm), the RSA encryption algorithm, etc.
[0068] More specifically, the target file data is encrypted using a block encryption algorithm, and each time only the block data of a preset length (BlockLength) is encrypted to generate ciphertext of equal length. Therefore, when the file position and data length to be written or read are not integer multiples of BlockLength, the file read / write position and length need to be adjusted to integer multiples of BlockLength, and the insufficient padding data at the end needs to be saved additionally.
[0069] It can be understood that the metadata file corresponding to the target file can store the corresponding second key and the complementary data generated by the block encryption.
[0070] In this embodiment, by directly setting a hook function in the kernel of the database management system, it is possible to respond quickly to the operation instructions of the database, and call the custom operation function to perform ciphertext operations on the target files in the database. Since the hook function is set at the kernel level, the ciphertext operation based on the custom operation function is faster and more efficient, which effectively reduces the performance loss of database encryption. This embodiment can realize the encryption requirements of the database without relying on the database TDE plug-in or trigger view characteristics, and support the requirements of the national secret algorithm. Moreover, it also performs relatively ideal in terms of transparency, versatility and performance, so that the database encryption product can not only meet the security compliance requirements, but also be truly put into use in the production system.
[0071] Furthermore, based on the above-mentioned first embodiment of the database management method of the present application, a second embodiment of the database management method of the present application is proposed. When the target file is empty, the "performing a ciphertext operation on the target file in the database by using the custom operation function" in step S20 is further refined, including:
[0072] Step S211, calling a preset random number generator module through a custom write operation function to generate a first key;
[0073] Step S212, obtaining the unencrypted data to be written corresponding to the write operation instruction;
[0074] Step S213, encrypting the unencrypted data to be written in groups based on the first key to obtain encrypted data to be written, and writing the encrypted data to be written into the target file;
[0075] Step S214, encrypting the first key to obtain a second key;
[0076] Step S215: create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
[0077] Specifically, this embodiment introduces the steps to be performed by the database management system when the custom operation function is a custom write operation function and the target file is empty. First, a preset random number generator module is called through the custom write operation function, and the random number generator module is responsible for generating the first key required for encryption. Since the first key is randomly generated, it can be ensured that it is difficult to guess or crack.
[0078] After the first key is generated, the database management system needs to obtain the unencrypted data to be written corresponding to the write operation instruction. The unencrypted data to be written is usually the original data that the user or application wants to write into the database.
[0079] The database management system then uses the first key generated in the first step to perform group encryption on the unencrypted data to be written. This means that the unencrypted data to be written is divided into fixed-size data groups (or blocks), and each data group is encrypted using the same key. The encrypted data is called "encrypted data to be written". Afterwards, the database management system writes the encrypted data to be written into the target file.
[0080] In order to ensure the security of the first key, the database management system also needs to encrypt the first key to obtain the second key. This step is usually completed using another key (which may be the hardware security module of the database management system or another key protected by a strong password) to ensure that even if the second key is leaked, the attacker cannot easily obtain the first key. Furthermore, the database management system will create a corresponding metadata file for the target file. By writing the second key to the metadata file corresponding to the target file, it can be quickly retrieved when needed to decrypt the target file. This metadata file contains some additional information about the target file, the most important of which is the second key. Of course, if padding data is generated during the process of group encryption of unencrypted data to be written, the padding data can also be stored in the metadata file corresponding to the target file.
[0081] The above process ensures the security of the data in the database, because only by obtaining the second key and decrypting the second key to obtain the first key can the original unencrypted data be decrypted and accessed. At the same time, through the block encryption method, the system can efficiently process a large amount of data without the need to perform a one-time encryption or decryption operation on the entire database file.
[0082] by Figure 3 For example, Figure 3 This is a schematic diagram of data writing involved in the database management method of this application. Figure 3 The a in the figure shows the data structure of the database file named "mysql-bin.000001". Its data is divided into several data groups (or blocks) according to the preset length (denoted as BlockLength). Each data group is of equal length. The total length of the entire database file is denoted as Length. Figure 3 b in the figure shows the situation where data needs to be padded. If Length is not an integer multiple of BlockLength, [Group N.2] and [Group N.1] need to be padded to the length BlockLength, so that the data can be encrypted in groups. The encrypted data of [Group 1] to [Group N.1] is written into the mysql-bin.000001 file, and the encrypted data of the padded length of Group N.2 is written into the mysql-bin.000001.meta file (that is, the metadata file corresponding to the mysql-bin.000001 file).
[0083] Combination Figure 4 , Figure 4This is a schematic diagram of the custom write operation function involved in the database management method of this application. It can be seen that during the execution of the custom write operation function, the target file needs to be locked first, and then it is determined whether it is empty. If the target file is empty, the corresponding steps of this embodiment are executed to complete the data writing to the target file, and then the target file is unlocked.
[0084] In this embodiment, when the target file is empty, a custom write operation function is used to automatically generate a key, encrypt data, and create a metadata file, thereby realizing transparent encryption and storage of data, effectively simplifying the encryption process, enhancing data security, and reducing the risk of data leakage.
[0085] Furthermore, based on the above-mentioned first embodiment of the database management method of the present application, a third embodiment of the database management method of the present application is proposed. When the target file is not empty, the "performing a ciphertext operation on the target file in the database by the custom operation function" in step S20 is further refined, including:
[0086] Step S221, reading the second key in the metadata file corresponding to the target file through a custom write operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system;
[0087] Step S222, decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module;
[0088] Step S223, decrypting the encrypted data to be modified in the target file in groups based on the first key to obtain unencrypted data to be modified;
[0089] Step S224, obtaining the unencrypted data to be written corresponding to the write operation instruction;
[0090] Step S225, combining the unencrypted data to be written with the unencrypted data to be modified to obtain unencrypted combined data;
[0091] Step S226: Encrypt the unencrypted combined data in groups based on the first key to obtain encrypted combined data, and write the encrypted combined data into the target file.
[0092] Specifically, this embodiment introduces the steps to be performed by the database management system when the custom operation function is a custom write operation function and the target file is not empty. First, the database management system uses the custom write operation function to read the metadata file corresponding to the target file. This metadata file is pre-created in the database management system and contains the second key.
[0093] After obtaining the second key, it needs to be decrypted to obtain the original first key. Since the second key is obtained by encrypting the first key, this step requires the use of a corresponding decryption algorithm and key (which may be the hardware security module of the database management system or another key protected by a strong password) to decrypt the second key and restore the first key.
[0094] After obtaining the first key, the database management system can use the first key to decrypt the encrypted data to be modified stored in the target file in groups, thereby obtaining the unencrypted data to be modified. Further, the database management system needs to obtain the unencrypted data to be written corresponding to the write operation instruction. The encrypted data to be written is the new data that the user or application wants to write to the target file, which has not yet been encrypted. Then, the unencrypted data to be written is combined with the unencrypted data to be modified to generate an unencrypted combined data. This may require merging the two data according to a certain rule or algorithm so that they can be correctly processed in the subsequent encryption process. Finally, the database management system will use the first key to encrypt the unencrypted combined data in groups. This means that the data will be divided into blocks (or groups) of fixed size, and each block will be encrypted using the first key to obtain encrypted combined data. The encrypted combined data will then be written to the target file, replacing the original encrypted data to be modified.
[0095] It is worth noting that if the encrypted data to be modified has corresponding complementary data, and the complementary data is stored in the metadata file, then before using the first key to decrypt the encrypted data to be modified stored in the target file in groups, it is necessary to obtain the complementary data from the metadata file corresponding to the target file, and then use the first key and the complementary data to decrypt the encrypted data to be modified stored in the target file in groups.
[0096] The above process ensures the security of the data in the database, because only by obtaining the second key and decrypting the second key to obtain the first key can the original unencrypted data be decrypted and accessed. At the same time, by combining the unencrypted data to be written with the unencrypted data to be modified and then encrypting them, it can ensure that both the newly written data and the original data are protected, avoiding the risk of data leakage or tampering.
[0097] by Figure 5 For example, Figure 5 This is a schematic diagram of data modification involved in the database management method of this application. Figure 5 a in the figure shows the data structure of the database file named "test_table.ibd". The original starting position POS and original length Length of the data to be written need to be adjusted to Figure 5The adjusted start position POS2 and the adjusted length Length2 in b in . The processing process is: read out the entire block of [Group 2] and [Group M] and decrypt the data, then encrypt the decrypted [Group 2.1] + [Unencrypted data to be written] + [Group M.2] as a whole and write it to the test_table.ibd file according to POS2 and Length2. Note: If (POS+Length) falls on [Group N] at the end of the file, then the data of [Group N.2] needs to be read from test_table.ibd.meta (the metadata file corresponding to test_table.ibd), and the new [Group N.2] obtained after encryption is overwritten and written back to the test_table.ibd.meta file.
[0098] Combination Figure 4 , Figure 4 This is a schematic diagram of the custom write operation function involved in the database management method of this application. It can be seen that during the execution of the custom write operation function, the target file needs to be locked first, and then it is determined whether it is empty. If the target file is not empty, the corresponding steps of this embodiment are executed to complete the data modification of the target file, and then the target file is unlocked.
[0099] In this embodiment, when the target file is not empty, the encrypted data is decrypted and modified by reading the second key in the metadata file, thereby protecting the existing data in the database. At the same time, the new data is encrypted and written, ensuring the integrity and consistency of the data and enhancing the security and reliability of the database.
[0100] Further based on the above-mentioned first embodiment of the database management method of the present application, a fourth embodiment of the database management method of the present application is proposed, and the "performing a ciphertext operation on the target file in the database by the custom operation function" in step S20 is further refined, including:
[0101] Step S231, reading the second key in the metadata file corresponding to the target file through a custom read operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system;
[0102] Step S232, decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module;
[0103] Step S233: decrypt the encrypted data to be read in the target file in groups based on the first key to obtain unencrypted data to be read, wherein the encrypted data to be read is encrypted in groups based on the first key in advance.
[0104] Specifically, this embodiment introduces the steps to be performed by the database management system when the custom operation function is a custom read operation function and the target file is not empty. First, the database management system uses the custom read operation function to access the metadata file corresponding to the target file. This metadata file is pre-created in the database management system and contains the encrypted second key, which is the key for subsequent decryption operations.
[0105] After reading the second key, the database management system needs to decrypt it to obtain the original first key. This decryption process usually requires the use of a specific decryption algorithm and a corresponding key (which may be the database management system's hardware security module or other strong password-protected key) to complete.
[0106] After successfully obtaining the first key, the database management system can use it to decrypt the encrypted data to be read stored in the target file. Since the encrypted data to be read is pre-encrypted in groups based on the first key, the database management system needs to use the first key to decrypt each group according to the same group size and encryption algorithm. The decrypted data is the unencrypted data to be read, which can be further processed or used by the system or application.
[0107] It is worth noting that if the encrypted data to be read has corresponding complementary data, and the complementary data is stored in the metadata file, then before using the first key to decrypt the encrypted data to be read stored in the target file in groups, it is necessary to obtain the complementary data from the metadata file corresponding to the target file, and then use the first key and the complementary data to decrypt the encrypted data to be read stored in the target file in groups.
[0108] Combination Figure 4 , Figure 4 This is a schematic diagram of the custom write operation function involved in the database management method of this application. It can be seen that during the execution of the custom write operation function, the target file needs to be locked first, and then it is determined whether it is empty. If the target file is not empty, the corresponding steps of this embodiment are executed to complete the data modification of the target file, and then the target file is unlocked.
[0109] by Figure 6 For example, Figure 6 This is a schematic diagram of data reading involved in the database management method of this application. Figure 6 a in the figure shows the data structure of the database file named "mysql-bin.000001". The original starting position POS and original length Length of the data to be written need to be adjusted to Figure 6The adjusted start position POS2 and the adjusted length Length2 in b in . The processing process is: read out the continuous packets from [packet 2] to [packet M] and decrypt the data, and then return the decrypted [packet 2.2] to [packet M.1] interval data to the upper layer. Note: If (POS+Length) falls on [packet N] at the end of the file, then the data of [packet N.2] needs to be read from mysql-bin.000001.meta (the metadata file corresponding to the mysql-bin.000001 file).
[0110] Combination Figure 7 , Figure 7 This is a schematic diagram of a custom read operation function involved in the database management method of this application. It can be seen that during the execution of the custom read operation function, the target file needs to be locked first, and then the corresponding steps of this embodiment are executed to complete the data reading of the target file, and finally the target file is unlocked.
[0111] In this embodiment, the transparent decryption of encrypted data in the database is realized through the custom read operation function, and the user can obtain the original data without worrying about the encryption details. This enhances the readability and usability of the data, while ensuring the security of the data during transmission and storage, and effectively preventing data leakage.
[0112] Furthermore, based on the first embodiment of the database management method of the present application, a fifth embodiment of the database management method of the present application is proposed. In step S10, in response to an operation instruction on the database, before calling the corresponding custom operation function through a hook function preset in the kernel of the database management system, the method further includes:
[0113] Step S011, calling a preset random number generator module through a preset initialization function to generate a first key;
[0114] Step S012, encrypting the data of the unencrypted file stored in the database in groups based on the first key to obtain a corresponding temporary file;
[0115] Step S013, overwriting the unencrypted file with the temporary file to obtain the target file;
[0116] Step S014, encrypting the first key to obtain a second key;
[0117] Step S015: create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
[0118] Specifically, the database management system is designed as two core modules. One is the initialization module, which is mainly used to perform static initial encryption conversion on the data of the original production system; the other is the encryption and decryption module, which is used to dynamically encrypt and decrypt the database files during the operation of the database system. The specific role of the encryption and decryption module has been described in Figure 2 It is reflected in the relevant description. This embodiment combines Figure 8 To introduce the system initialization mechanism.
[0119] The database management system first calls a preset initialization function, and then calls the random number generator module through the initialization function to generate a first key.
[0120] After the first key is generated, the data of the unencrypted file stored in the database is encrypted using the first key. The encryption here is group encryption, which means that the data of the unencrypted file will be divided into groups (or blocks) of a certain size, and each group will be encrypted using the first key. The encrypted data will be stored in a temporary file, which contains the encrypted file content.
[0121] After encryption is completed, the database management system will overwrite the original unencrypted file with this temporary file. This means that the original unencrypted file will be replaced by the encrypted temporary file to form a new encrypted file, called the target file. This step ensures that the files stored in the database are already encrypted, improving data security.
[0122] In addition, the database management system will re-encrypt the first key generated previously. This encryption process may use a different encryption algorithm or key to generate a second key. The second key is a further protection for the first key. Only users or systems with the correct key can decrypt the first key and then decrypt the target file.
[0123] Finally, the database management system will create a corresponding metadata file for the target file. This metadata file stores some additional information about the target file, the most important of which is the second key. The second key is written into the metadata file to facilitate the quick retrieval of this key when the target file needs to be decrypted or modified later.
[0124] The purpose of the above process is to encrypt the files in the database to ensure that even if the database is illegally accessed, the content of the files will not be easily leaked. Through block encryption and secondary key protection, this process improves the security and confidentiality of data.
[0125] Combination Fig. 9 , Fig. 9This is a schematic diagram of the initialization function involved in the database management method of this application. It can be seen that during the execution of the initialization function, the database service needs to be stopped first, and then the corresponding steps of this embodiment are executed to complete the group encryption of the unencrypted file. It is worth noting that if the group encryption process generates corresponding padding data, the padding data can be stored in the corresponding metadata file.
[0126] In this embodiment, the database management system can initialize and encrypt the unencrypted files in the database, generate the target file and its corresponding metadata file, and the entire initialization process enhances the overall security of the database.
[0127] Furthermore, based on the second to fifth embodiments above, a sixth embodiment of the database management method of the present application is proposed, and the method further includes:
[0128] Step S021, if the group encryption process corresponding to the target file generates padding data, the padding data is obtained and stored in the metadata file corresponding to the target file, wherein the padding data is used to group decrypt the data of the target file.
[0129] Specifically, in the above embodiments, if padding data is generated during the block encryption process, the database management system will obtain and store it in the metadata file corresponding to the target file. The "padding data" here refers to some additional data that needs to be added during block encryption because the data block size is not an integer multiple of the fixed encryption block size to ensure that all data can be correctly encrypted.
[0130] Padding is a filling mechanism that adds extra bytes to the end of the data to make the total length of the data an integer multiple of the encrypted block size. The values of these extra bytes are usually generated according to a specific pattern, such as all zeros, specific byte values, or values calculated from the data itself. The purpose of padding is to ensure the integrity and security of the data, because during the decryption process, these padding data will be identified and removed to restore the integrity of the original data.
[0131] In the encryption process, padding data is indispensable. However, padding data itself is also part of the encryption process, so it is also necessary in the decryption process. In order to ensure the smooth progress of the decryption process, the system needs to store the padding data in the metadata file corresponding to the target file. In this way, when the target file needs to be decrypted, the database management system can obtain the padding data from the metadata file and perform the decryption operation together with the encrypted data to obtain the original unencrypted data.
[0132] In this embodiment, the storage of the padding data ensures the integrity of the grouped encrypted data, and during the decryption process, the data can be used to accurately restore the original data. This feature improves the reliability of the encrypted data, reduces the risk of data damage or tampering, and further enhances the security of the database. In addition, the padding data is stored in the metadata file and does not occupy the storage space of the database, which effectively improves the storage space utilization of the database.
[0133] Furthermore, based on the above-mentioned first embodiment of the database management method of the present application, a seventh embodiment of the database management method of the present application is proposed, and the "response to the operation instruction on the database, calling the corresponding custom operation function through the hook function preset in the kernel of the database management system" in step S10 is further refined, including:
[0134] Step S11, in response to the operation instruction on the database, intercepting the corresponding original operation function through the hook function;
[0135] Step S12: If the original operation function meets the preset function type condition and the target file meets the preset file type condition, the corresponding custom operation function is called through the hook function.
[0136] Specifically, the database management system first listens to or waits for operation instructions to the database. When such an operation instruction appears, the database management system triggers a hook function, which intercepts the original operation function corresponding to the operation instruction through the hook function. This interception mechanism allows the database management system to insert custom logic or behavior before or after the execution of the original operation function.
[0137] After the hook function intercepts the original operation function, the database management system checks whether two conditions are met at the same time:
[0138] (1) Preset function type condition: used to determine whether the intercepted original operation function belongs to a specific type or category. For example, the database management system may only focus on those original operation functions involving file reading and writing or data modification. Only when the original operation function meets this condition will the database management system proceed to the next step.
[0139] (2) Preset file type condition: used to determine whether the target file (i.e., the file involved in the operation instruction) is of a specific type or format.
[0140] If both conditions are met, the database management system will call the corresponding custom operation function through the hook function. This custom operation function is written according to system requirements or security policies to replace or expand the functions of the original operation function. In this way, the database management system actually calls the custom operation function instead of the original operation function according to the operation instruction.
[0141] In this embodiment, the original operation function is intercepted and checked by the hook function, and the custom operation function is called only when it meets specific conditions. This method improves the flexibility and security of database operations and ensures that only operations that meet the conditions will trigger the execution of the custom operation function.
[0142] Furthermore, based on the first to seventh embodiments of the database management method of the present application, an eighth embodiment of the database management method of the present application is proposed. This embodiment introduces the deployment method of the database management system.
[0143] Combination Fig.10 , Fig.11 , Fig.10 This is the first schematic diagram of the deployment method involved in the database management method of this application. Fig.11 This is the second schematic diagram of the deployment method involved in the database management method of the present application. The method steps involved in the first to seventh embodiments of the database management method of the present application are encapsulated into an encryption plug-in and deployed in the database management system. At the same time, the permission gateway module is deployed in a reverse proxy manner to parse various database operations such as DCL (data control language), DML (data manipulation language), DDL (data definition language) used by database users to connect to the database, and match them with the rule base of the permission management module. Users who have the authority to view plain text data will return plain text, and unauthorized users will see cipher text or blank or masked characters. It can be understood that Fig.10 Information Department, Administration Department, Finance Department, Other Departments, and Fig.11 The legal users and unauthorized users can be regarded as part of the client. The database management system is connected to the switch in communication. The switch is set in the data link between the client and the database. The operation instruction is issued by the client.
[0144] More specifically, for Fig.10 The database cluster deployment method can effectively avoid encryption and decryption failures caused by single point failures without affecting business. In addition, the database management system can dynamically encrypt access to different roles and real-time system docking, and provide application layer account and proxy account access control services. Fig.11 The database management system is connected to the client and the database. The database management system can help users encrypt data and store it in the database. It can ensure fine-grained control of access rights during the access process, ensuring user data security without affecting the user experience.
[0145] In this embodiment, each step of the database management method is encapsulated as an encryption plug-in and deployed in the database management system, and combined with the authority gateway module of the reverse proxy, transparent encryption and authority control of database operations are achieved. This method enhances data security and user privacy protection, while improving the flexibility and scalability of the system.
[0146] In addition, the embodiment of the present application also provides a database management device, the database management system comprising:
[0147] A calling module, used for responding to an operation instruction on a database and calling a corresponding custom operation function through a hook function preset in the kernel of the database management system;
[0148] The operation module is used to perform ciphertext operation on the target file in the database through the custom operation function.
[0149] Optionally, the database management system is communicatively connected to a switch, the switch is arranged in a data link between the client and the database, and the operation instruction is issued by the client.
[0150] For the principle and implementation process of implementing database management in this embodiment, please refer to the above embodiments and will not be repeated here.
[0151] In addition, an embodiment of the present application further proposes a computer-readable storage medium, on which a database management program is stored. When the database management program is executed by a processor, the steps of the database management method described above are implemented.
[0152] Since the database management program adopts all the technical solutions of all the aforementioned embodiments when executed by the processor, it has at least all the beneficial effects brought by all the technical solutions of all the aforementioned embodiments, which will not be described one by one here.
[0153] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0154] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0155] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as above, including several instructions for a database management system (which can be a mobile phone, computer, server, controlled terminal, or network device, etc.) to execute the method of each embodiment of the present application.
[0156] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A database management method, characterized in that: The method is applied to a database management system, and the method comprises: In response to an operation instruction on a database, a corresponding custom operation function is called through a hook function preset in the kernel of the database management system; Performing ciphertext operation on the target file in the database through the custom operation function; When the target file is empty, the step of performing a ciphertext operation on the target file in the database by using the custom operation function comprises: Calling a preset random number generator module through a custom write operation function to generate a first key; Obtaining the unencrypted data to be written corresponding to the write operation instruction; Encrypting the unencrypted data to be written in groups based on the first key to obtain encrypted data to be written, and writing the encrypted data to be written into the target file; Encrypting the first key to obtain a second key; Create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
2. The database management method according to claim 1, characterized in that: In the case that the target file is not empty, the step of performing a ciphertext operation on the target file in the database by using the custom operation function comprises: Reading a second key in a metadata file corresponding to the target file through a custom write operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system; Decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module; Decrypting the encrypted data to be modified in the target file in groups based on the first key to obtain unencrypted data to be modified; Obtaining unencrypted data to be written corresponding to the write operation instruction; Combining the unencrypted data to be written with the unencrypted data to be modified to obtain unencrypted combined data; The unencrypted combined data is encrypted in groups based on the first key to obtain encrypted combined data, and the encrypted combined data is written into the target file.
3. The database management method according to claim 1, characterized in that: The step of performing a ciphertext operation on the target file in the database by using the custom operation function comprises: Reading a second key in a metadata file corresponding to the target file through a custom read operation function, wherein the metadata file corresponding to the target file is pre-created in the database management system; Decrypting the second key to obtain a first key, wherein the first key is generated by a preset random number generator module; The encrypted data to be read in the target file is decrypted in groups based on the first key to obtain unencrypted data to be read, wherein the encrypted data to be read is encrypted in groups based on the first key in advance.
4. The database management method according to claim 1, characterized in that: Before the step of calling the corresponding custom operation function through the hook function preset in the kernel of the database management system in response to the operation instruction on the database, the method further includes: Calling a preset random number generator module through a preset initialization function to generate a first key; Encrypting the data of the unencrypted file stored in the database in groups based on the first key to obtain a corresponding temporary file; Overwriting the unencrypted file with the temporary file to obtain the target file; Encrypting the first key to obtain a second key; Create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
5. The database management method according to any one of claims 2 to 4, characterized in that: The method further comprises: If the group encryption process corresponding to the target file generates padding data, the padding data is obtained and stored in the metadata file corresponding to the target file, wherein the padding data is used to perform group decryption on the data of the target file.
6. The database management method according to claim 1, characterized in that: The step of calling the corresponding custom operation function through a hook function preset in the kernel of the database management system in response to the operation instruction on the database includes: In response to an operation instruction on the database, intercepting a corresponding original operation function through the hook function; If the original operation function meets the preset function type condition, and the target file meets the preset file type condition, the corresponding custom operation function is called through the hook function.
7. A database management system, characterized in that: The database management system comprises: A calling module, used for responding to an operation instruction on a database and calling a corresponding custom operation function through a hook function preset in the kernel of the database management system; An operation module, used for performing a ciphertext operation on a target file in the database through the custom operation function; The operation module is also used to, when the target file is empty, call a preset random number generator module through a custom write operation function to generate a first key; obtain unencrypted data to be written corresponding to the write operation instruction; group-encrypt the unencrypted data to be written based on the first key to obtain encrypted data to be written, and write the encrypted data to be written into the target file; encrypt the first key to obtain a second key; create a metadata file corresponding to the target file, and write the second key into the metadata file corresponding to the target file, wherein the metadata file corresponding to the target file is used to perform ciphertext operations on the target file.
8. The database management system according to claim 7, characterized in that: The database management system is in communication connection with a switch, the switch is arranged in a data link between a client and the database, and the operation instruction is issued by the client.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a database management program, and when the database management program is executed by the processor, the steps of the database management method according to any one of claims 1 to 6 are implemented.
