Persistent file encryption method and device, electronic equipment and storage medium
By encrypting Redis's persistent data, the problem of low data security in the prior art is solved, and the encryption protection of data in the stored procedure is realized, reducing the risk of data being maliciously utilized.
Patent Information
- Application Number
- CN202411739143.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, Redis's persistence mechanism directly saves data from memory to disk, resulting in low security of data and the risk of malicious acquisition and utilization.
Provide a persistent file encryption method. By obtaining Redis configuration information, when triggering a preset persistence policy, the key-value pair data in memory is divided into data blocks to be encrypted, and these data blocks are encrypted according to the configuration information, and finally the encrypted data blocks are stored on the local disk.
By encrypting the data, it is ensured that even if the data is maliciously accessed or stolen by the attacker, the data cannot be read and utilized directly, which reduces the security risks of the data and improves the security of the data.
Smart Images

Figure CN119783123A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of database technology, and in particular to a method, device, electronic device and storage medium for encrypting a persistent file. Background Art
[0002] Redis (Remote Dictionary Server) is a high-performance in-memory database that stores data in memory to achieve fast read and write operations. However, the data in memory will be lost when the system restarts or crashes, so Redis provides a persistence mechanism to save the data in memory to disk to ensure data persistence and recoverability.
[0003] However, the relevant persistence mechanism is to save data directly from memory to disk. Although this process is simple and efficient, there is a security risk that the data may be maliciously acquired and used, so there is a problem of low data security. Summary of the invention
[0004] The embodiments of the present application provide a persistent file encryption method, device, electronic device and storage medium to solve the problem of low data security caused by directly saving data from memory to disk in the related art.
[0005] In a first aspect, an embodiment of the present application provides a persistent file encryption method, which is applied to a remote dictionary service, wherein the remote dictionary service stores key-value pair data, and the key-value pair data is stored in a memory, and the method includes:
[0006] Obtaining configuration information of the remote dictionary service;
[0007] In the case where a preset persistence strategy is triggered, the key-value pair data stored in the memory is divided into a plurality of data blocks to be encrypted;
[0008] For any of the data blocks to be encrypted, encrypt the data block to be encrypted according to the configuration information to obtain a target encrypted data block;
[0009] The target encrypted data blocks are stored in database files in the local disk respectively.
[0010] Optionally, the acquiring configuration information of the remote dictionary service includes:
[0011] Obtaining a configuration file of the remote dictionary service;
[0012] Setting configuration items in the configuration file;
[0013] When the configuration item is set, the configuration item is set to obtain configuration information of the remote dictionary service.
[0014] Optionally, the configuration information includes whether the persistent file encryption switch is turned on;
[0015] Before the step of dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted, the method includes:
[0016] Determine whether the persistent encryption switch is turned on;
[0017] When the persistent encryption switch is turned on, a step of dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted is performed.
[0018] Optionally, the configuration information includes a target persistent file encryption algorithm;
[0019] The encrypting the to-be-encrypted data block according to the configuration information to obtain the target encrypted data block comprises:
[0020] Obtaining a target encryption key corresponding to the target persistent file encryption algorithm;
[0021] The data block to be encrypted is encrypted according to the target encryption key to obtain a target encrypted data block.
[0022] Optionally, after the step of storing the target encrypted data blocks respectively in database files in the local disk, the method includes:
[0023] When the remote dictionary service is started, obtaining the database file from the local disk;
[0024] Loading the database file into the memory;
[0025] When the database file is loaded into the memory, the database file is decrypted according to the configuration information to obtain a target decrypted file.
[0026] Optionally, decrypting the database file according to the configuration information to obtain a target decrypted file includes:
[0027] Determine whether the persistent encryption switch is turned on;
[0028] When the persistent encryption switch is turned on, dividing the database file into a plurality of data blocks to be decrypted;
[0029] Get the target decryption key corresponding to the target persistent file encryption algorithm;
[0030] For any of the data blocks to be decrypted, decrypt the data block to be decrypted according to the target decryption key to obtain a target decrypted data block;
[0031] The target decrypted data blocks constitute a target decrypted file.
[0032] Optionally, after the step of decrypting the database file according to the configuration information to obtain a target decrypted file, the method includes:
[0033] Performing a data integrity check on the target decrypted file to obtain a data integrity check result;
[0034] When the data integrity check result is passed, a key space of the remote dictionary service is established.
[0035] In a second aspect, an embodiment of the present application provides a persistent file encryption device, the device comprising:
[0036] A remote dictionary service configuration module, used to obtain configuration information of the remote dictionary service;
[0037] A data partitioning module, used for partitioning the key-value pair data stored in the memory into a plurality of data blocks to be encrypted when a preset persistence strategy is triggered;
[0038] A data encryption module, used for encrypting any of the data blocks to be encrypted according to the configuration information to obtain a target encrypted data block;
[0039] The persistence module is used to store the target encrypted data blocks in database files in the local disk respectively.
[0040] Optionally, the remote dictionary service configuration module includes:
[0041] A configuration file acquisition submodule, used to acquire the configuration file of the remote dictionary service;
[0042] A configuration item setting submodule, used to set configuration items in the configuration file;
[0043] The configuration information determination submodule is used to set the configuration item after completing the setting of the configuration item, and obtain the configuration information of the remote dictionary service.
[0044] Optionally, the configuration information includes whether the persistent file encryption switch is turned on;
[0045] The device comprises:
[0046] A first persistent encryption switch determination module, used to determine whether the persistent encryption switch is turned on;
[0047] The first data partitioning module is used to execute the step of partitioning the key-value pair data stored in the memory into a plurality of data blocks to be encrypted when the persistent encryption switch is turned on.
[0048] Optionally, the configuration information includes a target persistent file encryption algorithm;
[0049] The data encryption module comprises:
[0050] A target encryption key acquisition submodule, used to acquire a target encryption key corresponding to the target persistent file encryption algorithm;
[0051] The data block encryption submodule is used to encrypt the to-be-encrypted data block according to the target encryption key to obtain a target encrypted data block.
[0052] Optionally, the device comprises:
[0053] A database file acquisition module, used for acquiring the database file from the local disk when the remote dictionary service is started;
[0054] A database file loading module, used for loading the database file into the memory;
[0055] The database file decryption module is used to decrypt the database file according to the configuration information to obtain a target decrypted file after the database file is loaded into the memory.
[0056] Optionally, the database file decryption module includes:
[0057] A persistent encryption switch determination submodule, used to determine whether the persistent encryption switch is turned on;
[0058] A database file division submodule, used for dividing the database file into a number of data blocks to be decrypted when the persistent encryption switch is turned on;
[0059] The target decryption key acquisition submodule is used to obtain the target decryption key corresponding to the target persistent file encryption algorithm;
[0060] A data block decryption submodule, used for decrypting any of the data blocks to be decrypted according to the target decryption key to obtain a target decrypted data block;
[0061] The target decryption file determination submodule is used for forming the target decryption file from the target decryption data blocks.
[0062] Optionally, the device comprises:
[0063] A data integrity verification module is used to perform a data integrity verification on the target decrypted file to obtain a data integrity verification result;
[0064] The key space establishment module is used to establish the key space of the remote dictionary service when the data integrity check result is passed.
[0065] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor, wherein the processor is configured to execute the instructions to implement any of the persistent file encryption methods described above.
[0066] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any of the persistent file encryption methods described above.
[0067] In an embodiment of the present application, the configuration information of the remote dictionary service is obtained, and when the preset persistence strategy is triggered, the key-value pair data stored in the memory is divided into several data blocks to be encrypted. For any data block to be encrypted, the encrypted data block is encrypted according to the configuration information to obtain the target encrypted data, and the target encrypted data blocks are stored in the database file in the local disk. The present application ensures that the data has been encrypted before being stored in the local disk by dividing the key-value pair data stored in the memory into data blocks and encrypting the data. Even if the data is maliciously accessed or stolen by an attacker, since the data has been encrypted and protected, the attacker cannot directly read and use the data, thereby reducing the security risk of the data, improving the security of the data, and solving the problem of low data security in the prior art.
[0068] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0070] Figure 1This is one of the step flow charts of a persistent file encryption method provided in an embodiment of the present application;
[0071] Figure 2 This is the second step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0072] Figure 3 This is the third step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0073] Figure 4 This is the fourth step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0074] Figure 5 This is the fifth step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0075] Figure 6 This is the sixth step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0076] Figure 7 This is the seventh step flow chart of a persistent file encryption method provided in an embodiment of the present application;
[0077] Figure 8 It is a device block diagram of a persistent file encryption device provided in an embodiment of the present application;
[0078] Fig. 9 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0079] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0080] To facilitate understanding, the terms involved in the embodiments of the present application are first briefly introduced.
[0081] 1. Redis (Remote Dictionary Server)
[0082] Redis is an open source NoSql in-memory database that supports a variety of data structures, such as strings, hashes, lists, sets, ordered sets, etc., and provides a variety of feature-rich operation commands to meet the needs of various application scenarios. Redis features include fast read and write speeds, support for persistence, support for transactions, publish and subscribe, etc., making it the preferred data storage solution for many applications.
[0083] 2. Persistence
[0084] Persistence means saving data (such as objects in memory) to a storage device (such as a disk) that can be permanently saved. The main application of persistence is to store objects in memory in a database, or in a disk file, XML (Extensible Markup Language) data file, etc.
[0085] 3. Persistent file encryption
[0086] Persistent file encryption refers to encrypting the files generated by Redis when persisting data to protect the data contained in them from being read by unauthorized accessors. Encrypting persistent files can improve the confidentiality and security of data, prevent sensitive information from being maliciously accessed or tampered with, and help meet security compliance requirements.
[0087] In conjunction with the accompanying drawings, an energy management method, device, storage medium and vehicle for an extended-range vehicle provided in an embodiment of the present application are described in detail through specific embodiments and their application scenarios.
[0088] Figure 1 is a flowchart of a method for encrypting a persistent file provided by an embodiment of the present application. Figure 1 As shown, the method is applied to a remote dictionary service, and the method includes:
[0089] Step 101: Obtain configuration information of a remote dictionary service.
[0090] Step 102: When a preset persistence strategy is triggered, the key-value pair data stored in the memory is divided into a number of data blocks to be encrypted.
[0091] Step 103: for any data block to be encrypted, encrypt the data block to be encrypted according to the configuration information to obtain a target encrypted data block.
[0092] Step 104: Store the target encrypted data blocks into database files in the local disk respectively.
[0093] It should be noted that, in the embodiment of the present application, key-value pair data is stored in the remote dictionary service, and the key-value pair data is stored in the memory.
[0094] The configuration information of the remote dictionary service can be obtained in advance. When the preset persistence strategy is triggered automatically or manually, the key-value pair data of the remote dictionary service stored in the memory is divided into blocks to obtain a number of key-value pair data blocks, which are a number of data blocks to be encrypted.
[0095] The automatic triggering method may be that when the remote dictionary service reaches a certain time interval or the key-value pair data in the remote dictionary service reaches a certain amount, the preset persistence strategy will be automatically triggered. The external manual triggering method may be that the preset persistence strategy is manually triggered through a remote dictionary service command (such as a BGSAVE command).
[0096] When data segmentation is completed, any of the data blocks to be encrypted can be encrypted according to the configuration information of the remote dictionary service obtained in advance to obtain a target encrypted data block. When several target encrypted data blocks are obtained, the target encrypted data blocks are stored in a database file in a local disk, and the database file can be an RDB (Redis database).
[0097] In addition, before data segmentation and data encryption of the key-value pair data of the remote dictionary service stored in the memory, a child process can be created through the fork() system call, and the child process can be used to perform data segmentation, data encryption, storage of the target encrypted data block to the local disk, and data decryption. The child process shares the physical memory space with the parent process (the virtual space is inconsistent), which ensures that the data operation of the parent process is not interfered with, and the parent process can continue to provide external services.
[0098] This application ensures that the data has been encrypted before being stored on the local disk by dividing the key-value pair data stored in the memory into data blocks and encrypting the data. Even if the data is maliciously accessed or stolen by an attacker, the attacker cannot directly read and use the data because the data has been encrypted and protected, thereby reducing the security risk of the data, improving the security of the data, and solving the problem of low data security in the prior art. In addition, this application can also prevent data leakage by encrypting the data, that is, prevent the data from being intercepted and leaked during transmission and storage, especially when the disk or storage medium is stolen; and it can also prevent data tampering, that is, the data cannot be tampered with or forged without authorization, ensuring the integrity and credibility of the data during storage. In addition, through data block division and parallel encryption, this application enables the system to perform encryption operations more efficiently, improving the efficiency and performance of data encryption processing.
[0099] Further, in the embodiments of the present application, Figure 2 As shown, step 101 may further include the following steps:
[0100] Step 201, obtaining a configuration file of a remote dictionary service.
[0101] Step 202: Set configuration items in the configuration file.
[0102] Step 203: After completing the configuration item setting, the configuration item is set to obtain the configuration information of the remote dictionary service.
[0103] It should be noted that, in an embodiment of the present application, a configuration file of the remote dictionary service is obtained in advance. When the configuration file of the remote dictionary service is obtained, the configuration items are set in the configuration file. The set configuration items may be a persistent file encryption switch and a persistent file encryption algorithm. When the configuration items are set, the set configuration items are set to obtain the configuration information of the remote dictionary service. Specifically, if the configuration item is a persistent file encryption switch, the persistent file encryption switch may be set to on or off; if the configuration item is a persistent file encryption algorithm, the persistent file encryption algorithm may be set to the national secret algorithm SM4 or the international algorithm AES, and the set national secret algorithm SM4 or the international algorithm AES is the target persistent file encryption algorithm. Therefore, the configuration information of the remote dictionary service may include whether the persistent file encryption switch is turned on and the target persistent file encryption algorithm.
[0104] In addition, in order to meet compliance and high data security or confidentiality scenarios, the persistent file encryption switch is turned on by default. When the persistent file encryption switch is turned on, the persistent file encryption algorithm defaults to the national encryption algorithm SM4.
[0105] This application improves the remote dictionary service by setting configuration items (persistent file encryption switch and persistent file encryption algorithm) in the configuration file of the remote dictionary service and setting the configuration items, so that the remote dictionary service has the attribute of data encryption, realizes flexible setting of data encryption, and improves the flexibility, configurability, compliance and security of the remote dictionary service.
[0106] Further, in the embodiments of the present application, Figure 3 As shown, before the step of "dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted", the following steps may also be included:
[0107] Step 301, determine whether the persistent encryption switch is turned on.
[0108] Step 302, when the persistent encryption switch is turned on, execute the step of dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted.
[0109] It should be noted that in the embodiment of the present application, before dividing the key-value pair data stored in the memory into a number of data blocks to be encrypted, it can be determined whether the persistent encryption switch is turned on. If the persistent encryption switch is turned on, the step of dividing the key-value pair data stored in the memory into a number of data blocks to be encrypted is performed.
[0110] The present application determines whether the persistent encryption switch is turned on. When the persistent encryption switch is turned on, the application further executes the step of dividing the key-value pair data stored in the memory into a number of data blocks to be encrypted. By determining the persistent encryption switch, the application can flexibly choose whether to enable the encryption function in different scenarios. This flexibility enables the system to adapt to different security requirements and environments.
[0111] Further, in the embodiments of the present application, Figure 4 As shown, step 103 may also include the following steps:
[0112] Step 401, obtaining a target encryption key corresponding to a target persistent file encryption algorithm.
[0113] Step 402: encrypt the data block to be encrypted according to the target encryption key to obtain a target encrypted data block.
[0114] It should be noted that in the embodiment of the present application, the target persistent file encryption algorithm is obtained. When the target persistent file encryption algorithm is obtained, the encryption key corresponding to the target persistent file encryption algorithm is obtained, and the encryption key corresponding to the target persistent file encryption algorithm is the target encryption key. Specifically, if the target persistent file encryption algorithm is the national secret algorithm SM4, the encryption key corresponding to the national secret algorithm SM4 is obtained, and the encryption key corresponding to the national secret algorithm SM4 is the target encryption key; if the target persistent file encryption algorithm is the international algorithm AES, the encryption key corresponding to the international algorithm AES is obtained, and the encryption key corresponding to the international algorithm AES is the target encryption key.
[0115] When the target encryption key is obtained, each data block to be encrypted is encrypted using the target encryption key, thereby obtaining a plurality of target encrypted data blocks.
[0116] This application encrypts the encrypted data blocks by using encryption algorithms that comply with national and international standards (national encryption algorithm SM4 or international algorithm AES). This not only ensures that the data storage and processing process complies with relevant laws, regulations and industry standards, such as GDPR and China's "Cybersecurity Law", but also meets the data protection requirements and certification standards of specific industries (such as finance and medical care), thereby improving the compliance and credibility of the system.
[0117] Further, in the embodiments of the present application, Figure 5 As shown, after step 104, the following steps may also be included:
[0118] Step 501: When the remote dictionary service is started, a database file is obtained from a local disk.
[0119] Step 502, loading the database file into the memory.
[0120] Step 503, when the database file is loaded into the memory, the database file is decrypted according to the configuration information to obtain a target decrypted file.
[0121] It should be noted that in the embodiment of the present application, when the remote dictionary service is started or restarted, the database file is obtained from the local disk. It should be noted that the database file is composed of a number of target encrypted data blocks.
[0122] When the database file is obtained, the database file is loaded into the memory. When the database file is loaded into the memory, the database file is decrypted according to the configuration information of the remote dictionary service (whether the persistent file encryption switch is turned on and the target persistent file encryption algorithm) to obtain the target decrypted file.
[0123] This application decrypts the database file according to the configuration information after loading the database file into the memory. The encrypted stored data includes the user's personal information, transaction records and other sensitive information. This ensures that only authorized decryption operations can restore this information and prevent sensitive data leakage. It ensures that the user's privacy information is not leaked during storage and transmission, and enhances the user's confidence in data security.
[0124] Further, in the embodiments of the present application, Figure 6 As shown, step 503 may also include the following steps:
[0125] Step 601, determine whether the persistent encryption switch is turned on.
[0126] Step 602: When the persistent encryption switch is turned on, the database file is divided into a number of data blocks to be decrypted.
[0127] Step 603: Obtain a target decryption key corresponding to the target persistent file encryption algorithm.
[0128] Step 604: for any data block to be decrypted, decrypt the data block to be decrypted according to the target decryption key to obtain a target decrypted data block.
[0129] Step 605: The target decrypted data blocks form a target decrypted file.
[0130] It should be noted that in the embodiment of the present application, when the database file is loaded into the memory, it can be determined whether the persistent encryption switch is turned on. When the persistent encryption switch is turned on, the database file can be divided into data blocks to obtain a number of data blocks, and the obtained data blocks are the data blocks to be decrypted.
[0131] Get the target persistent file encryption algorithm. It should be noted that the target persistent file encryption algorithm here is consistent with the encryption algorithm used when encrypting the data. Specifically, if the national secret algorithm SM4 is used to encrypt the data, the national secret algorithm SM4 is also used when decrypting the data; if the international algorithm AES is used to encrypt the data, the international algorithm AES is also used when decrypting the data.
[0132] When the target persistent file encryption algorithm is obtained, the decryption key corresponding to the target persistent file encryption algorithm is obtained. The decryption key corresponding to the target persistent file encryption algorithm is the target decryption key. Specifically, if the target persistent file encryption algorithm is the national secret algorithm SM4, the decryption key corresponding to the national secret algorithm SM4 is obtained, and the decryption key corresponding to the national secret algorithm SM4 is the target decryption key; if the target persistent file encryption algorithm is the international algorithm AES, the decryption key corresponding to the international algorithm AES is obtained, and the decryption key corresponding to the international algorithm AES is the target decryption key.
[0133] For any of the data blocks to be decrypted, the target decryption key is used to decrypt the data block to be decrypted, thereby obtaining a number of target decrypted data blocks, which together constitute a target decryption file.
[0134] By judging the status of the persistent file encryption switch, the system can dynamically decide whether to perform the decryption operation. This mechanism enhances the flexibility and controllability of data decryption, allowing the user to choose whether to enable the decryption function according to actual needs. In addition, by dividing data blocks and performing parallel decryption, the system can perform decryption operations more efficiently, improving the efficiency and performance of data decryption processing.
[0135] Further, in the embodiments of the present application, Figure 7 As shown, after step 503, the following steps may also be included:
[0136] Step 701, perform data integrity check on the target decrypted file to obtain a data integrity check result.
[0137] Step 702: If the data integrity check result is passed, a key space of a remote dictionary service is established.
[0138] It should be noted that in the embodiment of the present application, after obtaining the target decrypted file, in order to ensure that the target decrypted file has not been tampered with or damaged, the target decrypted file can be subjected to a data integrity check by means of a checksum, a cyclic redundancy check, a hash function, etc., to obtain a data integrity check result. If the data integrity check result is passed, the key space of the remote dictionary service can be re-established. After completing these steps, the remote dictionary service can accept business connections from clients.
[0139] This application can effectively detect the consistency and integrity of the target decrypted file by performing a data integrity check on the target decrypted file, ensuring the correctness and reliability of the target decrypted file. In addition, this application will rebuild the key space of the remote dictionary service only when the data integrity check passes. This mechanism ensures the integrity and consistency of the data and avoids service anomalies caused by data corruption or tampering. In addition, the reconstruction of the key space is a key step in restoring the remote dictionary service, ensuring that the remote dictionary service can provide normal business connections to the outside world.
[0140] Corresponding to the method provided in the above-mentioned embodiment of the persistent file encryption method of the present application, see Figure 8 The present application also provides a device block diagram of a persistent file encryption device. In this embodiment, the device includes:
[0141] A remote dictionary service configuration module 801 is used to obtain configuration information of a remote dictionary service;
[0142] The data partitioning module 802 is used to partition the key-value pair data stored in the memory into a number of data blocks to be encrypted when a preset persistence strategy is triggered;
[0143] The data encryption module 803 is used to encrypt any data block to be encrypted according to the configuration information to obtain a target encrypted data block;
[0144] The persistence module 804 is used to store the target encrypted data blocks in database files in the local disk respectively.
[0145] Optionally, the remote dictionary service configuration module 801 includes:
[0146] The configuration file acquisition submodule is used to obtain the configuration file of the remote dictionary service;
[0147] The configuration item setting submodule is used to set configuration items in the configuration file;
[0148] The configuration information determination submodule is used to set the configuration items after completing the configuration items and obtain the configuration information of the remote dictionary service.
[0149] Optionally, the configuration information includes whether the persistent file encryption switch is turned on;
[0150] The device includes:
[0151] A first persistent encryption switch determination module, used to determine whether the persistent encryption switch is turned on;
[0152] The first data partitioning module is used to execute the step of partitioning the key-value pair data stored in the memory into a plurality of data blocks to be encrypted when the persistent encryption switch is turned on.
[0153] Optionally, the configuration information includes a target persistent file encryption algorithm;
[0154] The data encryption module 803 includes:
[0155] The target encryption key acquisition submodule is used to obtain the target encryption key corresponding to the target persistent file encryption algorithm;
[0156] The data block encryption submodule is used to encrypt the data block to be encrypted according to the target encryption key to obtain the target encrypted data block.
[0157] Optionally, the device comprises:
[0158] The database file acquisition module is used to obtain the database file from the local disk when the remote dictionary service is started;
[0159] Database file loading module, used to load database files into memory;
[0160] The database file decryption module is used to decrypt the database file according to the configuration information after the database file is loaded into the memory to obtain the target decrypted file.
[0161] Optionally, the database file decryption module includes:
[0162] The persistent encryption switch judgment submodule is used to judge whether the persistent encryption switch is turned on;
[0163] The database file division submodule is used to divide the database file into several data blocks to be decrypted when the persistent encryption switch is turned on;
[0164] The target decryption key acquisition submodule is used to obtain the target decryption key corresponding to the target persistent file encryption algorithm;
[0165] The data block decryption submodule is used to decrypt any data block to be decrypted according to the target decryption key to obtain a target decrypted data block;
[0166] The target decryption file determination submodule is used for forming a target decryption file from target decryption data blocks.
[0167] Optionally, the device comprises:
[0168] A data integrity verification module is used to perform data integrity verification on the target decrypted file and obtain a data integrity verification result;
[0169] The key space establishment module is used to establish the key space of the remote dictionary service when the data integrity check result is passed.
[0170] Fig. 9 This is a structural diagram of an electronic device M00 provided in an embodiment of the present application. In the figure, the electronic device M00 includes a processor M01 and a memory M02. The memory M02 stores programs or instructions that can be run on the processor M01. When the program or instructions are executed by the processor M01, the various steps of the above-mentioned persistent file encryption method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0171] In an embodiment of the present application, the memory M02 may be used to store software programs and various data. The memory M02 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory M02 may include a volatile memory or a non-volatile memory, or the memory M02 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory M02 in the embodiment of the present application includes but is not limited to these and any other suitable types of memories.
[0172] The processor M01 may include one or more processing units; optionally, the processor M01 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor M01.
[0173] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned persistent file encryption method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0174] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0175] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned persistent file encryption method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0176] 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 such an understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0177] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A persistent file encryption method, characterized in that: Applied to a remote dictionary service, wherein the remote dictionary service stores key-value pair data, and the key-value pair data is stored in a memory, and the method comprises: Obtaining configuration information of the remote dictionary service; In the case where a preset persistence strategy is triggered, the key-value pair data stored in the memory is divided into a plurality of data blocks to be encrypted; For any of the data blocks to be encrypted, encrypt the data block to be encrypted according to the configuration information to obtain a target encrypted data block; The target encrypted data blocks are stored in database files in the local disk respectively.
2. The method according to claim 1, characterized in that The acquiring of the configuration information of the remote dictionary service includes: Obtaining a configuration file of the remote dictionary service; Setting configuration items in the configuration file; When the configuration item is set, the configuration item is set to obtain configuration information of the remote dictionary service.
3. The method according to claim 1, characterized in that The configuration information includes whether the persistent file encryption switch is turned on; Before the step of dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted, the method includes: Determine whether the persistent encryption switch is turned on; When the persistent encryption switch is turned on, a step of dividing the key-value pair data stored in the memory into a plurality of data blocks to be encrypted is performed.
4. The method according to claim 1, characterized in that The configuration information includes a target persistent file encryption algorithm; The encrypting the to-be-encrypted data block according to the configuration information to obtain the target encrypted data block comprises: Obtaining a target encryption key corresponding to the target persistent file encryption algorithm; The data block to be encrypted is encrypted according to the target encryption key to obtain a target encrypted data block.
5. The method according to claim 1, characterized in that After the step of storing the target encrypted data blocks in database files in the local disk respectively, the method includes: When the remote dictionary service is started, obtaining the database file from the local disk; Loading the database file into the memory; When the database file is loaded into the memory, the database file is decrypted according to the configuration information to obtain a target decrypted file.
6. The method according to claim 2, characterized in that Decrypting the database file according to the configuration information to obtain a target decrypted file comprises: Determine whether the persistent encryption switch is turned on; When the persistent encryption switch is turned on, dividing the database file into a plurality of data blocks to be decrypted; Get the target decryption key corresponding to the target persistent file encryption algorithm; For any of the data blocks to be decrypted, decrypt the data block to be decrypted according to the target decryption key to obtain a target decrypted data block; The target decrypted data blocks constitute a target decrypted file.
7. The method according to claim 5, characterized in that After the step of decrypting the database file according to the configuration information to obtain a target decrypted file, the method includes: Performing a data integrity check on the target decrypted file to obtain a data integrity check result; When the data integrity check result is passed, a key space of the remote dictionary service is established.
8. A persistent file encryption device, characterized in that: The device comprises: A remote dictionary service configuration module, used to obtain configuration information of the remote dictionary service; A data partitioning module, used for partitioning the key-value pair data stored in the memory into a plurality of data blocks to be encrypted when a preset persistence strategy is triggered; A data encryption module, used for encrypting any of the data blocks to be encrypted according to the configuration information to obtain a target encrypted data block; The persistence module is used to store the target encrypted data blocks in database files in the local disk respectively.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the persistent file encryption method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the persistent file encryption method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Memory data persistence method and device, storage medium and computer equipment
CN112685360A
Password modification method, device and system, storage medium and electronic equipment
CN115964697A
Internal memory database encryption method, database system and electronic equipment
CN116150792A