Data storage method and apparatus, and storage medium and electronic device

By performing segmentation encryption processing and key encryption storage on the file data in the GridFS system, the problem of poor data security when the GridFS system is attacked is solved and high-security data storage is achieved.

WO2024187914A1PCT designated stage expired Publication Date: 2024-09-19CHINA TELECOM CLOUD TECH CO LTD

Patent Information

Application Number
PCT/CN2023/142732
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-12-14
Filing Date
2023-12-28
Publication Date
2024-09-19

AI Technical Summary

Technical Problem

When the GridFS system is attacked, file data is stored in plain text, resulting in poor data security and easy leakage of file data.

Method used

The file is divided into multiple data blocks using data segmentation processing, and the key is generated and encrypted through the key distribution module. The data blocks are encrypted and stored using SM4 and SM2 cryptographic algorithms. The attacker can only obtain the encrypted data ciphertext. Unable to obtain clear text.

Benefits of technology

It effectively avoids data leakage, improves data security, and ensures that even if the file system is attacked, the attacker cannot crack the key that encrypts the data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023142732_19092024_PF_FP_ABST
    Figure CN2023142732_19092024_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present invention are a data storage method and apparatus, and a storage medium and an electronic device. The method comprises: when a file storage request is received, performing data segmentation processing on a file to be stored, so as to obtain a plurality of chunks; sending a key request to a key distribution module, so as to obtain a first key ciphertext and a first key pair index; on the basis of a preset key library, determining a first private key ciphertext corresponding to the first key pair index; sending the first key ciphertext and the first private key ciphertext to a preset cipher machine, so that the cipher machine performs decryption processing on the first key ciphertext, so as to obtain a first key plaintext; performing data encryption processing on each chunk on the basis of the first key plaintext, so as to obtain a data ciphertext of each chunk; and storing the data ciphertext corresponding to each chunk, the first key ciphertext and the first key pair index. By means of the method in the present invention, distributed storage of file data is performed in the form of a ciphertext, such that an attacker cannot acquire original file data, and the data security can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Data storage method and device, storage medium and electronic device Technical Field

[0001] The present invention relates to the field of data storage technology, and in particular to a data storage method and device, a storage medium, and an electronic device. Background Art

[0002] Grid File System (GridFS) is a common file system used in data storage scenarios. GridFS is a distributed file storage system that can implement file data storage based on the MongoDB database.

[0003] Currently, the GridFS system typically stores files by dividing file data into blocks and storing each block in a database through distributed storage. When file data needs to be read, the data in the corresponding storage location is read on demand, and then the read data is spliced ​​to obtain the required file data.

[0004] In real-world applications, file systems are often targeted by attackers. If an attacker cracks the administrator's password, they can log in to the server and access file data in the file system, potentially stealing data. Based on existing data storage methods, the GridFS system stores file data in plaintext. When attacked, attackers can directly access the data, making the file system less secure.

[0005] Summary of the Invention

[0006] In view of this, an embodiment of the present invention provides a data storage method to solve the problem that when a file system is attacked, file data is easily leaked, resulting in poor data security.

[0007] The embodiment of the present invention further provides a data storage device to ensure the practical implementation and application of the above method.

[0008] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0009] A data storage method, comprising:

[0010] When a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain a plurality of data blocks corresponding to the first target file;

[0011] Sending a key request corresponding to the first target file to a preset key distribution module, causing the key distribution module to perform key distribution processing and obtain a first key ciphertext and a first key pair index;

[0012] Determining, based on a preset key library, a first private key ciphertext corresponding to the first key pair index; the key library stores ciphertexts of multiple key pairs, each ciphertext of the key pair including a public key ciphertext and a private key ciphertext; the first key ciphertext is ciphertext encrypted based on a target public key, where the target public key is the public key in the key pair corresponding to the first private key ciphertext;

[0013] Sending the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, causing the cryptographic machine to decrypt the first key ciphertext to obtain the first key plaintext;

[0014] Performing data encryption processing on each of the data blocks based on the first key plaintext to obtain data ciphertext corresponding to each of the data blocks;

[0015] Using the first key ciphertext and the first key pair index as metadata information corresponding to the first target file;

[0016] The data ciphertext and the metadata information corresponding to each data block are stored to complete the storage process of the first target file.

[0017] In the above method, optionally, the key distribution module performs key distribution processing, including:

[0018] Calling the cryptographic machine to perform key generation processing to obtain a first key; the first key is a key generated based on the SM4 cryptographic algorithm;

[0019] In the key library, determining the target public key ciphertext corresponding to the first target file;

[0020] Using the index of the key pair corresponding to the target public key ciphertext as the first key pair index;

[0021] The first key and the target public key ciphertext are sent to the cryptographic machine, so that the cryptographic machine encrypts the first key and uses the encryption result as the first key ciphertext.

[0022] In the above method, optionally, the process of the cryptographic machine decrypting the first key ciphertext includes:

[0023] Decrypting the first private key ciphertext based on a preset root key to obtain a first private key plaintext corresponding to the first private key ciphertext;

[0024] The first key ciphertext is decrypted based on the first private key plaintext, and the decryption result is used as the first key plaintext.

[0025] In the above method, optionally, each of the key pairs is a key generated based on the SM2 cryptographic algorithm.

[0026] The above method may optionally further include:

[0027] Performing a hash operation on the first target file according to a preset SM3 cryptographic algorithm to obtain an original text digest value corresponding to the first target file;

[0028] The original text summary value corresponding to the first target file is stored.

[0029] The above method may optionally further include:

[0030] When receiving a file read request corresponding to a second target file, determining ciphertexts of respective data blocks corresponding to the second target file;

[0031] Determine a second key ciphertext and a second key pair index corresponding to the second target file;

[0032] Obtaining, from the key library, a second private key ciphertext corresponding to the second key pair index;

[0033] Sending the second key ciphertext and the second private key ciphertext to the cryptographic machine, causing the cryptographic machine to decrypt the second key ciphertext to obtain the second key plaintext;

[0034] Decrypting each data block ciphertext based on the second key plaintext to obtain a data block plaintext corresponding to each data block ciphertext;

[0035] Performing data splicing processing on the plaintext of each data block to obtain a data splicing result;

[0036] Performing data verification on the data splicing result;

[0037] If the data verification of the data splicing result passes, the data splicing result is used as the file data of the second target file.

[0038] In the above method, optionally, the process of performing data verification on the data splicing result includes:

[0039] Determining an original text digest value corresponding to the second target file;

[0040] Performing a hash operation on the data concatenation result according to a preset SM3 cryptographic algorithm to obtain a current digest value corresponding to the second target file;

[0041] Comparing the original text digest value corresponding to the second target file with the current digest value;

[0042] If the original text digest value corresponding to the second target file is the same as the current digest value, it is determined that the data verification of the data splicing result has passed.

[0043] A data storage device comprising:

[0044] a data segmentation unit configured to, upon receiving a file storage request corresponding to a first target file, perform data segmentation processing on the first target file to obtain a plurality of data blocks corresponding to the first target file;

[0045] a key distribution unit, configured to send a key request corresponding to the first target file to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index;

[0046] a private key acquisition unit, configured to determine, based on a preset key library, a first private key ciphertext corresponding to the first key pair index; the key library storing ciphertexts of multiple key pairs, each of which includes a public key ciphertext and a private key ciphertext; the first key ciphertext being ciphertext encrypted based on a target public key, the target public key being the public key in the key pair corresponding to the first private key ciphertext;

[0047] a key decryption unit, configured to send the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, so that the cryptographic machine decrypts the first key ciphertext to obtain a first key plaintext;

[0048] a data encryption unit, configured to perform data encryption processing on each of the data blocks based on the first key plaintext to obtain data ciphertext corresponding to each of the data blocks;

[0049] a metadata unit, configured to use the first key ciphertext and the first key pair index as metadata information corresponding to the first target file;

[0050] The data storage unit is used to store the data ciphertext and the metadata information corresponding to each data block to complete the storage process of the first target file.

[0051] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the data storage method as described above.

[0052] An electronic device includes a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the data storage method as described above.

[0053] A data storage method provided by the above-mentioned embodiment of the present invention includes: when a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain multiple data blocks corresponding to the first target file; a key request corresponding to the first target file is sent to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index; based on a preset key library, a first private key ciphertext corresponding to the first key pair index is determined; the key library stores ciphertexts of multiple key pairs, and the ciphertext of each key pair includes a public key ciphertext and a private key ciphertext; the first key ciphertext is ciphertext obtained by encrypting based on a target public key, and the target public key is the public key in the key pair corresponding to the first private key ciphertext; the first key ciphertext and the first private key ciphertext are sent to a preset cipher machine, so that the cipher machine decrypts the first key ciphertext to obtain a first key plaintext; Each data block is encrypted based on the first key plaintext to obtain the data ciphertext corresponding to each data block; the first key ciphertext and the first key pair index are used as metadata information corresponding to the first target file; the data ciphertext and metadata information corresponding to each data block are stored to complete the storage process of the first target file. By applying the method provided in an embodiment of the present invention, file data can be encrypted and then distributed stored, and the key used to encrypt the file data is encrypted and stored. If the file system is attacked, the attacker can only obtain the data ciphertext but not the data plaintext, and it is difficult to crack the key that encrypts the data, which is conducive to preventing data leakage and improving data security. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0055] FIG1 is a flow chart of a data storage method provided by an embodiment of the present invention;

[0056] FIG2 is an exemplary diagram of the architecture of a data storage system provided by an embodiment of the present invention;

[0057] FIG3 is a signaling diagram of a data storage process provided by an embodiment of the present invention;

[0058] FIG4 is a schematic structural diagram of a data storage device provided by an embodiment of the present invention;

[0059] FIG5 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0060] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0061] In this application, the terms "comprises," "comprising," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not preclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0062] An embodiment of the present invention provides a data storage method, which can be applied to a grid file system GridFS. The execution subject can be a server of the system. The method flow chart of the method is shown in FIG1 , and includes:

[0063] S101: When a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain multiple data blocks corresponding to the first target file;

[0064] In the method provided by an embodiment of the present invention, when a server receives a request from a user to store a file, the server considers the file to be stored as a first target file and performs data segmentation on the file's data, dividing the file into multiple data blocks of a specified size. In the GridFS system, data blocks are generally called chunks.

[0065] S102: Sending a key request corresponding to the first target file to a preset key distribution module, causing the key distribution module to perform key distribution processing and obtain a first key ciphertext and a first key pair index;

[0066] In the method provided by an embodiment of the present invention, a key distribution module is pre-set, which is used to respond to key requests and distribute the ciphertext of the key used to encrypt data and the index information of the key pair used to decrypt the ciphertext based on a predetermined key distribution strategy.

[0067] The server sends a key request corresponding to the first target file to the key distribution module. In response, the key distribution module determines the first key ciphertext and the first key pair index and returns this information to the server. The server then obtains the first key ciphertext and the first key pair index. The first key ciphertext is the ciphertext of a symmetric key. The first key pair index is an index that indicates an asymmetric key pair. The first key ciphertext is data encrypted using the public key of the key pair associated with the first key pair index.

[0068] S103: Determine, based on a preset key library, a first private key ciphertext corresponding to the first key pair index;

[0069] In the method provided by an embodiment of the present invention, a key library is pre-established, storing the ciphertext of multiple key pairs, each of which includes a public key ciphertext and a private key ciphertext. Each key pair stored in the key library can be pre-generated by a hardware cryptographic machine, which encrypts the public key and private key of each key pair using a preset key (such as the machine's root key) to obtain the ciphertext of each key pair. A corresponding index is generated for each key pair, and the ciphertext of each key pair and its corresponding index are stored in the key library.

[0070] After obtaining the first key pair index, the server can search the key pair ciphertext corresponding to the first key pair index in the key library, obtain the private key ciphertext from the key pair ciphertext, and use this private key ciphertext as the first private key ciphertext. The first key ciphertext is the ciphertext encrypted using the target public key, which is the public key in the key pair corresponding to the first private key ciphertext. In actual applications, each private key ciphertext in the key library can also be stored in a designated cache area, and the server can obtain the corresponding private key ciphertext from the cache area.

[0071] S104: Sending the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, causing the cryptographic machine to decrypt the first key ciphertext to obtain a first key plaintext;

[0072] In the method provided by an embodiment of the present invention, the server can send the first key ciphertext and the first private key ciphertext to a preset cryptographic machine. This cryptographic machine is a hardware cryptographic machine, which is the same hardware cryptographic machine used to generate each key pair mentioned above. After receiving the first key ciphertext and the first private key ciphertext, the cryptographic machine can decrypt the first key ciphertext based on a preset key decryption strategy. The decryption result is the first key plaintext, that is, the plaintext data of the first key ciphertext. The decryption result is fed back to the server, and the server can obtain the first key plaintext.

[0073] S105: Perform data encryption processing on each data block based on the first key plaintext to obtain data ciphertext corresponding to each data block;

[0074] In the method provided by the embodiment of the present invention, the server can use the first key plaintext to perform data encryption processing on each data block corresponding to the first target file to obtain the encryption result of each data block, that is, the data ciphertext corresponding to each data block.

[0075] S106: Using the first key ciphertext and the first key pair index as metadata information corresponding to the first target file;

[0076] In the method provided by the embodiment of the present invention, the server uses the first key ciphertext and the first key pair index as metadata of the first target file to indicate decryption information of the first target file.

[0077] S107: Storing the data ciphertext and the metadata information corresponding to each data block to complete the storage process of the first target file.

[0078] In the method provided by an embodiment of the present invention, the server can store the data ciphertext corresponding to each data block as the file data of the first target file in a distributed manner to the corresponding location, and store the first key ciphertext and the first key pair index as the metadata of the first target file in an associated manner.

[0079] Based on the method provided by the embodiment of the present invention, when a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain multiple data blocks corresponding to the first target file; a key request corresponding to the first target file is sent to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index; based on a preset key library, a first private key ciphertext corresponding to the first key pair index is determined; the first key ciphertext and the first private key ciphertext are sent to a preset cipher machine, so that the cipher machine decrypts the first key ciphertext to obtain a first key plaintext; data encryption processing is performed on each data block based on the first key plaintext to obtain a data ciphertext corresponding to each data block; the first key ciphertext and the first key pair index are used as metadata information corresponding to the first target file; the data ciphertext and metadata information corresponding to each data block are stored to complete the storage process of the first target file. By applying the method provided in the embodiment of the present invention, file data can be encrypted and then stored in a distributed manner, and the key used to encrypt the file data can be encrypted and stored. If the file system is attacked, the attacker can only obtain the data ciphertext but not the data plaintext, and it is difficult to crack the key for the encrypted data, which is conducive to avoiding data leakage and improving data security.

[0080] Based on the method shown in FIG1 , in the method provided by the embodiment of the present invention, the process of the key distribution module performing key distribution processing mentioned in step S102 includes:

[0081] Calling the cryptographic machine to perform key generation processing to obtain a first key; the first key is a key generated based on the SM4 cryptographic algorithm;

[0082] In the method provided by the embodiment of the present invention, the key distribution module can call a preset cryptographic machine to generate a symmetric key according to the SM4 cryptographic algorithm, and use the symmetric key as the first key. The SM4 cryptographic algorithm is an existing national secret algorithm and will not be described in detail here.

[0083] In the key library, determining the target public key ciphertext corresponding to the first target file;

[0084] In the method provided by the embodiment of the present invention, the key distribution module can obtain the public key ciphertext of a key pair from the key library to facilitate encrypting the first key, and use the obtained public key ciphertext as the target public key ciphertext.

[0085] Using the index of the key pair corresponding to the target public key ciphertext as the first key pair index;

[0086] In the method provided by an embodiment of the present invention, the key distribution module uses the key pair index corresponding to the target public key ciphertext as the first key pair index. Based on this index, the target public key ciphertext and its corresponding private key ciphertext can be matched in the key library. It is understood that the public key corresponding to the target public key ciphertext and the private key corresponding to the private key ciphertext corresponding to the target public key ciphertext form an asymmetric key pair.

[0087] The first key and the target public key ciphertext are sent to the cryptographic machine, so that the cryptographic machine encrypts the first key and uses the encryption result as the first key ciphertext.

[0088] In the method provided by an embodiment of the present invention, the key distribution module sends the first key and the target public key ciphertext to the cryptographic machine. The cryptographic machine can encrypt the first key based on a preset key encryption policy and feed the encryption result back to the key distribution module. This encryption result is the first key ciphertext. Specifically, upon receiving the first key and the target public key ciphertext, the cryptographic machine can decrypt the target public key ciphertext based on the preset key to obtain the plaintext data corresponding to the target public key ciphertext, namely, a public key. The decrypted public key is used as the encryption key to encrypt the first key, thereby obtaining the first key encryption result.

[0089] Based on the method shown in FIG1 , in the method provided by the embodiment of the present invention, the process of the cryptographic machine decrypting the first key ciphertext mentioned in step S104 includes:

[0090] Decrypting the first private key ciphertext based on a preset root key to obtain a first private key plaintext corresponding to the first private key ciphertext;

[0091] In the method provided by an embodiment of the present invention, after receiving the first key ciphertext and the first private key ciphertext, the cipher machine first uses the root key as the decryption key to perform data decryption processing on the first private key ciphertext to obtain the plaintext data of the first private key ciphertext, that is, the first private key plaintext, which is also a private key.

[0092] The first key ciphertext is decrypted based on the first private key plaintext, and the decryption result is used as the first key plaintext.

[0093] In the method provided by an embodiment of the present invention, after the cipher machine obtains the first private key plaintext, it uses the first private key plaintext as the decryption key, performs data result processing on the first key ciphertext, and obtains the first key plaintext, that is, the plaintext data of the first key ciphertext, that is, the first key mentioned in the previous embodiment.

[0094] Based on the method shown in FIG1 , in the method provided by an embodiment of the present invention, each of the key pairs is a key generated based on the SM2 cryptographic algorithm.

[0095] In the method provided in the embodiment of the present invention, the key library stores the ciphertext of multiple key pairs, which are asymmetric keys generated based on the SM2 cryptographic algorithm. The SM2 cryptographic algorithm is an elliptic curve public key cryptographic algorithm, which is an existing national secret algorithm and will not be described in detail here.

[0096] Based on the method shown in FIG1 , the method provided in the embodiment of the present invention further includes:

[0097] Performing a hash operation on the first target file according to a preset SM3 cryptographic algorithm to obtain an original text digest value corresponding to the first target file;

[0098] The original text summary value corresponding to the first target file is stored.

[0099] In the method provided by an embodiment of the present invention, when the server stores the first target file, it will perform a hash operation on the file data of the first target file based on the SM3 cryptographic algorithm, use the hash operation result as the original text digest value corresponding to the first target file, and store this original text digest value to facilitate subsequent data integrity verification of the first target file.

[0100] Based on the method shown in FIG1 , the method provided in the embodiment of the present invention further includes:

[0101] When receiving a file read request corresponding to a second target file, determining ciphertexts of respective data blocks corresponding to the second target file;

[0102] In the method provided by an embodiment of the present invention, when a server receives a request from a user to read file data, the file to be read is regarded as a second target file. In a distributed storage file system, the distributed data information of the stored files is stored as metadata to indicate which data blocks are stored in which locations in each file. When storing the second target file, the method shown in Figure 1 is used for storage, so what is actually stored is the data ciphertext of each data block of the second target file. Based on the metadata of the second target file, the server can obtain the ciphertext of each data block corresponding to the second target file from the corresponding storage location.

[0103] Determine a second key ciphertext and a second key pair index corresponding to the second target file;

[0104] In the method provided in an embodiment of the present invention, the server can obtain a second key ciphertext and a second key pair index from the metadata information corresponding to the second target file. The second key ciphertext is the ciphertext of the key used to encrypt the data blocks of the second target file when storing the second target file, and the second key pair index is the index of the key pair containing the encryption key of the second key ciphertext. It can be understood that the second key ciphertext for the second target file is similar to the first key ciphertext for the first target file in the above embodiment, and the second key pair index for the second target file is similar to the first key pair index for the first target file in the above embodiment.

[0105] Obtaining, from the key library, a second private key ciphertext corresponding to the second key pair index;

[0106] In the method provided by the embodiment of the present invention, the server can search the key pair ciphertext corresponding to the second key pair index in the key library, obtain the private key ciphertext in the key pair ciphertext, and use the private key ciphertext as the second private key ciphertext.

[0107] Sending the second key ciphertext and the second private key ciphertext to the cryptographic machine, causing the cryptographic machine to decrypt the second key ciphertext to obtain the second key plaintext;

[0108] In the method provided in this embodiment of the present invention, the server sends the second key ciphertext and the second private key ciphertext to the cryptographic machine. The cryptographic machine decrypts the second key ciphertext based on a preset key decryption policy, and the decryption result is the second key plaintext. The process by which the cryptographic machine decrypts the second key ciphertext is similar to the process by which the cryptographic machine decrypts the first key ciphertext. For details, refer to the description of step S104 in the previous embodiment and will not be repeated here.

[0109] Decrypting each data block ciphertext based on the second key plaintext to obtain a data block plaintext corresponding to each data block ciphertext;

[0110] In the method provided by the embodiment of the present invention, the server can use the second key plaintext as the decryption key to perform data decryption processing on each data block ciphertext of the second target file respectively to obtain the plaintext data of each data block ciphertext, that is, the data block plaintext corresponding to each data block ciphertext.

[0111] Performing data splicing processing on the plaintext of each data block to obtain a data splicing result;

[0112] In the method provided by an embodiment of the present invention, when storing file data, after the file is divided into multiple data blocks, each data block is arranged according to the order of the original data text, that is, each data block has its corresponding arrangement order. After the data blocks are encrypted and stored, the stored data block ciphertext is also associated with the arrangement order of the original data blocks.

[0113] When the server performs file reading processing on the second target file, it can perform data splicing on the plaintexts of the data blocks according to the arrangement order associated with the ciphertexts of the data blocks of the second target file to obtain a data splicing result.

[0114] Performing data verification on the data splicing result;

[0115] In the method provided by the embodiment of the present invention, the server may perform data verification on the data splicing result based on a preset data verification strategy to verify whether the read data is complete and correct.

[0116] If the data verification of the data splicing result passes, the data splicing result is used as the file data of the second target file.

[0117] In the method provided by an embodiment of the present invention, if the data verification result of the data splicing result indicates that the data verification has passed, the server will use the data splicing result as the file data of the second target file and feed it back to the user to complete the file reading process of the second target file.

[0118] In the method provided by the embodiment of the present invention, if the data verification of the data splicing result fails, a prompt indicating that the file is abnormal can be given.

[0119] On the basis of the method provided in the above embodiment, in the method provided in the embodiment of the present invention, the process of performing data verification on the data splicing result includes:

[0120] Determining an original text digest value corresponding to the second target file;

[0121] In the method provided by an embodiment of the present invention, the server can obtain the original text digest value corresponding to the second target file from pre-stored information. The original text digest value is the digest value obtained by performing a hash operation on the file data of the second target file through the SM3 cryptographic algorithm when storing the second target file.

[0122] Performing a hash operation on the data concatenation result according to a preset SM3 cryptographic algorithm to obtain a current digest value corresponding to the second target file;

[0123] In the method provided by the embodiment of the present invention, the server may perform a hash operation on the current data splicing result using the SM3 cryptographic algorithm, and use the hash operation result as the current digest value.

[0124] Comparing the original text digest value corresponding to the second target file with the current digest value;

[0125] In the method provided by the embodiment of the present invention, the original text digest value corresponding to the second target file is compared with the current digest value. If the original text digest value is different from the current digest value, it is considered that the data verification of the current data splicing result has failed.

[0126] If the original text digest value corresponding to the second target file is the same as the current digest value, it is determined that the data verification of the data splicing result has passed.

[0127] In the method provided by the embodiment of the present invention, if the original text digest value and the current digest value are the same, it means that the currently read data is the same as the stored data. At this time, it is considered that the data verification of the data splicing result has passed, that is, the verification pass is used as the data verification result.

[0128] Based on the method provided by the embodiment of the present invention, when reading a file, the integrity of the file data can be verified by comparing the digest values, which is beneficial to ensuring data integrity and facilitating the discovery of abnormal phenomena such as data tampering.

[0129] To better illustrate the method provided by the embodiments of the present invention, based on the methods provided in the previous embodiments and in combination with actual application scenarios, the embodiments of the present invention provide another data storage method. The method provided by the embodiments of the present invention can be implemented using a data storage system. This system is an instantiation of the data storage method shown in Figure 1. The system architecture diagram of this system can be shown in Figure 2. This system is a data storage system implemented based on the GridFS system. The GridFS system is commonly used in large file storage scenarios.

[0130] As shown in Figure 2, the data storage system provided by an embodiment of the present invention includes a key management module, a data calculation module, a data storage module, and a hardware cryptographic machine. The GridFS system uses two collections to store files: fs.chunks and fs.files. fs.chunks stores binary data for files, while fs.files stores metadata for files.

[0131] Next, the functions of each module in the system are briefly described.

[0132] Key management module: The key management module consists of a key distribution module and a key library. The key distribution module is responsible for generating and distributing keys, and the key library is responsible for storing public and private key pairs used by asymmetric encryption and decryption algorithms. The key distribution module mainly includes a key generation unit and a key distribution unit. The key generation unit is responsible for generating data encryption and decryption keys (i.e., keys used to encrypt and decrypt file data) and key encryption keys (i.e., keys used to encrypt and decrypt data encryption and decryption keys, which are the key pairs mentioned in the previous embodiments). The key encryption keys are of SM2 type, and the data encryption and decryption keys are of SM4 type, both of which are generated by hardware cryptographic machines. The key distribution unit is responsible for key distribution and forwarding, realizing the mutual transmission of keys between the data encryption and decryption unit and the key management module. The key library stores the ciphertext of the key encryption key and its index. The ciphertext is derived by the cipher machine creating the key and encrypting it with the root key. The key library is deployed in dual-master mode.

[0133] Data calculation module: The data calculation module includes a data encryption and decryption unit, a data summary unit, and a key cache. When performing file storage processing, the data encryption and decryption unit will first divide the file into multiple chunks (i.e., data blocks) according to the size of the chunk. When storing data, the SM4 algorithm is used to encrypt the file data of each chunk, and when reading data, the SM4 algorithm is used to decrypt the ciphertext of each chunk. The key used in the encryption and decryption process is the data encryption and decryption key generated by the key distribution module. It is encrypted with an asymmetric key and transmitted to the data encryption and decryption unit. The data encryption and decryption unit searches for the key encryption key through the index and uses the key to decrypt the data encryption and decryption key. The data summary unit uses the SM3 algorithm to perform a summary operation on the plaintext of the original file data to obtain a summary value. The key cache is mainly used to cache the private key of the key encryption key to improve decryption efficiency.

[0134] Data Storage Module: This module responds to read and write requests from the system. It stores the ciphertext of file data transferred by the Data Calculation Module in the data field of fs.chunks, stores the digest value in the sm3 value field of fs.files, and stores the ciphertext of the data encryption and decryption key and the index of the key encryption key in the file custom information of fs.files. A file has only one fs.files collection and can have multiple fs.chunks collections. The number of fs.chunks collections depends on the number of chunks the file is divided into, and each chunk is 256KB in size.

[0135] Hardware cipher machine: The hardware cipher machine is mainly responsible for creating SM2 key pairs, encrypting them with the root key inside the cipher machine, and exporting the SM2 key pair ciphertext, creating SM4 keys, and performing encryption and decryption, digest operations, etc.

[0136] Next, the specific implementation of the data storage process provided by the embodiment of the present invention is briefly described in conjunction with the signaling diagram shown in Figure 3. Based on the architecture shown in Figure 2, the method provided by the embodiment of the present invention mainly includes:

[0137] The key generation unit in the key distribution module creates an SM2 key pair through a cryptographic machine, encrypts the SM2 key pair using the root key in the cryptographic machine, stores the encrypted SM2 key pair in the key library, generates an index for each SM2 key pair, and then synchronizes the data in the key library to the key cache.

[0138] Based on the method provided in the embodiment of the present invention, the file storage process mainly includes:

[0139] When the system receives a request to write data, the data calculation module responds to the request;

[0140] The data summary unit makes an SM3 summary of the file data;

[0141] The data encryption and decryption unit divides the file data into chunks of 256KB chunk size and encrypts each chunk to obtain the ciphertext of each chunk. The process of encrypting each chunk to obtain the ciphertext of each chunk specifically includes:

[0142] The data encryption and decryption unit sends a key request to the key management module;

[0143] The key generation unit in the key distribution module calls the cipher machine to generate the SM4 key;

[0144] The key distribution unit in the key distribution module reads the public key ciphertext of the SM2 key pair from the key library, sends the ciphertext and the SM4 key plaintext to the cipher machine for encryption, and the cipher machine uses the root key to decrypt the SM2 public key ciphertext, and then uses the SM2 public key plaintext to encrypt the SM4 key;

[0145] The key distribution unit sends the SM2 key pair index and SM4 key ciphertext to the data encryption and decryption unit;

[0146] The data encryption and decryption unit reads the private key ciphertext of the SM2 key pair from the key buffer according to the index, and sends the private key ciphertext and the SM4 key ciphertext to the cipher machine for decryption. The cipher machine uses the root key to decrypt the SM2 private key ciphertext, and then uses the private key plaintext to decrypt the SM4 key ciphertext to obtain the SM4 key plaintext;

[0147] Each chunk is encrypted using the SM4 key plaintext.

[0148] The data calculation module transmits the digest value, data ciphertext, SM4 key ciphertext and SM2 key pair index to the data storage module for storage;

[0149] The storage process of the data storage module includes:

[0150] The data storage module creates fs.files and fs.chunks collections. The number of fs.chunks collections is the same as the number of split chunks.

[0151] Write _id (file ID), chunkSize, uploadDate (upload time), length (length), sm3 digest value, filename (file name), contentType (content type), metadata (metadata), etc. to the fs.files collection, and write the SM4 key ciphertext and the index of the SM2 key pair to the metadata;

[0152] Write _id, files_id, n, and data (data block data) into the fs.chunks collection, where files_id is the id of the fs.files collection, n is the order of the chunk, and data is the ciphertext binary data of the chunk.

[0153] Based on the method provided in the embodiment of the present invention, the file reading process mainly includes:

[0154] When the system receives a request to read data, the data calculation module responds to the request;

[0155] The data encryption and decryption unit requests data from the data storage module, decrypts the chunks, and then splices them into plain text in sequence. Specifically:

[0156] The data encryption and decryption unit requests data from the data storage module and obtains the corresponding chunk ciphertext, SM4 key ciphertext and SM2 key pair index;

[0157] Obtain the corresponding private key ciphertext from the key cache according to the index, send the private key ciphertext and SM4 key ciphertext to the cipher machine, the cipher machine uses the root key to decrypt the private key to obtain the private key plaintext, and uses the private key plaintext to decrypt the SM4 key ciphertext to obtain the SM4 key plaintext;

[0158] Use the SM4 key plaintext to decrypt each chunk and concatenate the chunk plaintext into file data according to the order.

[0159] Calculate the SM3 digest of the currently spliced ​​file data and compare the digest value with the pre-stored digest value of the original file data to verify whether the data has been tampered with;

[0160] If the digest values ​​are consistent, the plaintext data is returned to complete the file reading.

[0161] It is understood that the method provided in the embodiment of the present invention is an encrypted storage method for the GridFS distributed storage system based on the national encryption algorithm. In the embodiment of the present invention, GridFS encrypts the file data through envelope encryption and stores it in the fs.chunks collection. The encrypted data key is asymmetrically encrypted and the asymmetrically encrypted key is stored in fs.files to ensure the confidentiality of the file data. An SM3 digest value is generated for the file data, and this SM3 digest value replaces the original MD5 value of the GridFS system and is stored in fs.files to verify the integrity of the file.

[0162] Based on the method provided by the embodiment of the present invention, in a distributed storage scenario, file data is stored after envelope encryption, which is beneficial to improving data security, ensuring data confidentiality, and meeting the special storage requirements of confidential data. Envelope encryption combines the security of asymmetric keys with the low computational complexity of symmetric encryption, with a faster computing speed and a higher security level, improving storage security without affecting access speed. The various cryptographic algorithms used in the method provided by the embodiment of the present invention adopt national secret algorithms, which is beneficial to ensuring the independent control of encryption technology.

[0163] Corresponding to the data storage method shown in FIG1 , an embodiment of the present invention further provides a data storage device for implementing the method shown in FIG1 . The device has a schematic structural diagram shown in FIG4 , including:

[0164] The data segmentation unit 201 is configured to, upon receiving a file storage request corresponding to a first target file, perform data segmentation processing on the first target file to obtain a plurality of data blocks corresponding to the first target file;

[0165] The key distribution unit 202 is configured to send a key request corresponding to the first target file to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index;

[0166] A private key acquisition unit 203 is configured to determine, based on a preset key library, a first private key ciphertext corresponding to the first key pair index; the key library stores ciphertexts of multiple key pairs, each of which includes a public key ciphertext and a private key ciphertext; the first key ciphertext is ciphertext encrypted based on a target public key, where the target public key is the public key in the key pair corresponding to the first private key ciphertext;

[0167] a key decryption unit 204, configured to send the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, so that the cryptographic machine decrypts the first key ciphertext to obtain a first key plaintext;

[0168] A data encryption unit 205 is configured to perform data encryption processing on each data block based on the first key plaintext to obtain data ciphertext corresponding to each data block;

[0169] A metadata unit 206 is configured to use the first key ciphertext and the first key pair index as metadata information corresponding to the first target file;

[0170] The data storage unit 207 is used to store the data ciphertext and the metadata information corresponding to each data block to complete the storage process of the first target file.

[0171] By using the device provided by the embodiment of the present invention, file data can be encrypted and then stored in a distributed manner, and the key used to encrypt the file data can be encrypted and stored. If the file system is attacked, the attacker can only obtain the data ciphertext but not the data plaintext, and it is difficult to crack the key for the encrypted data, which is conducive to avoiding data leakage and improving data security.

[0172] Based on the device shown in Figure 4, the device provided by the embodiment of the present invention can be further expanded to multiple units. The functions of each unit can be found in the description of the various embodiments provided for the data storage method above, and no further examples will be given here.

[0173] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the data storage method as described above.

[0174] An embodiment of the present invention further provides an electronic device, the structure of which is shown in FIG5 . The electronic device includes a memory 301 and one or more instructions 302 . The one or more instructions 302 are stored in the memory 301 and are configured to be executed by one or more processors 303 to perform the following operations:

[0175] When a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain a plurality of data blocks corresponding to the first target file;

[0176] Sending a key request corresponding to the first target file to a preset key distribution module, causing the key distribution module to perform key distribution processing and obtain a first key ciphertext and a first key pair index;

[0177] Determining, based on a preset key library, a first private key ciphertext corresponding to the first key pair index; the key library stores ciphertexts of multiple key pairs, each ciphertext of the key pair including a public key ciphertext and a private key ciphertext; the first key ciphertext is ciphertext encrypted based on a target public key, where the target public key is the public key in the key pair corresponding to the first private key ciphertext;

[0178] Sending the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, causing the cryptographic machine to decrypt the first key ciphertext to obtain the first key plaintext;

[0179] Performing data encryption processing on each of the data blocks based on the first key plaintext to obtain data ciphertext corresponding to each of the data blocks;

[0180] Using the first key ciphertext and the first key pair index as metadata information corresponding to the first target file;

[0181] The data ciphertext and the metadata information corresponding to each data block are stored to complete the storage process of the first target file.

[0182] Each embodiment in this specification is described in a progressive manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple. For relevant parts, refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.

[0183] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0184] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A data storage method, characterized in that: include: When a file storage request corresponding to a first target file is received, data segmentation processing is performed on the first target file to obtain a plurality of data blocks corresponding to the first target file; Sending a key request corresponding to the first target file to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index; Based on a preset key library, determine a first private key ciphertext corresponding to the first key pair index; the key library stores ciphertexts of multiple key pairs, and the ciphertext of each key pair includes a public key ciphertext and a private key ciphertext; the first key ciphertext is a ciphertext encrypted based on a target public key, and the target public key is a public key in the key pair corresponding to the first private key ciphertext; Sending the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, so that the cryptographic machine decrypts the first key ciphertext to obtain a first key plaintext; Performing data encryption processing on each of the data blocks based on the first key plaintext to obtain data ciphertext corresponding to each of the data blocks; Using the first key ciphertext and the first key pair index as metadata information corresponding to the first target file; The data ciphertext and the metadata information corresponding to each of the data blocks are stored to complete the storage process of the first target file.

2. The method according to claim 1, characterized in that: The process of the key distribution module performing key distribution processing includes: Calling the cryptographic machine to perform key generation processing to obtain a first key; the first key is a key generated based on the SM4 cryptographic algorithm; In the key library, determining the target public key ciphertext corresponding to the first target file; Using the index of the key pair corresponding to the target public key ciphertext as the first key pair index; The first key and the target public key ciphertext are sent to the cryptographic machine, so that the cryptographic machine encrypts the first key and uses the encryption result as the first key ciphertext.

3. The method according to claim 1, characterized in that The process of the cryptographic machine decrypting the first key ciphertext includes: Decrypting the first private key ciphertext based on a preset root key to obtain a first private key plaintext corresponding to the first private key ciphertext; The first key ciphertext is decrypted based on the first private key plaintext, and the decryption result is used as the first key plaintext.

4. The method according to claim 1, characterized in that: Each of the key pairs is a key generated based on the SM2 cryptographic algorithm.

5. The method according to claim 1, characterized in that Also includes: According to a preset SM3 cryptographic algorithm, a hash operation is performed on the first target file to obtain an original text digest value corresponding to the first target file; The original text summary value corresponding to the first target file is stored.

6. The method according to claim 1, characterized in that Also includes: When receiving a file read request corresponding to a second target file, determining ciphertexts of respective data blocks corresponding to the second target file; Determine a second key ciphertext and a second key pair index corresponding to the second target file; Obtaining, from the key library, a second private key ciphertext corresponding to the second key pair index; Sending the second key ciphertext and the second private key ciphertext to the cryptographic machine, so that the cryptographic machine decrypts the second key ciphertext to obtain the second key plaintext; Performing data decryption processing on each of the data block ciphertexts based on the second key plaintext to obtain a data block plaintext corresponding to each of the data block ciphertexts; Performing data splicing processing on the plaintext of each data block to obtain a data splicing result; Performing data verification on the data splicing result; If the data verification of the data splicing result passes, the data splicing result is used as the file data of the second target file.

7. The method according to claim 6, characterized in that The process of performing data verification on the data splicing result includes: Determine an original text summary value corresponding to the second target file; According to a preset SM3 cryptographic algorithm, a hash operation is performed on the data splicing result to obtain a current digest value corresponding to the second target file; Comparing the original text digest value corresponding to the second target file with the current digest value; If the original text digest value corresponding to the second target file is the same as the current digest value, it is determined that the data verification of the data splicing result has passed.

8. A data storage device, characterized in that: include: a data segmentation unit, configured to, when receiving a file storage request corresponding to a first target file, perform data segmentation processing on the first target file to obtain a plurality of data blocks corresponding to the first target file; A key distribution unit, used for sending a key request corresponding to the first target file to a preset key distribution module, so that the key distribution module performs key distribution processing to obtain a first key ciphertext and a first key pair index; A private key acquisition unit, configured to determine, based on a preset key library, a first private key ciphertext corresponding to the first key pair index; the key library stores ciphertexts of multiple key pairs, each of which includes a public key ciphertext and a private key ciphertext; the first key ciphertext is a ciphertext encrypted based on a target public key, and the target public key is a public key in the key pair corresponding to the first private key ciphertext; A key decryption unit, used for sending the first key ciphertext and the first private key ciphertext to a preset cryptographic machine, so that the cryptographic machine decrypts the first key ciphertext to obtain a first key plaintext; A data encryption unit, configured to perform data encryption processing on each of the data blocks based on the first key plaintext to obtain data ciphertext corresponding to each of the data blocks; a metadata unit, configured to use the first key ciphertext and the first key pair index as metadata information corresponding to the first target file; The data storage unit is used to store the data ciphertext and the metadata information corresponding to each of the data blocks to complete the storage process of the first target file.

9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the data storage method according to any one of claims 1 to 7.

10. An electronic device, characterized in that: The device comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the data storage method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Secret key rotation method and device, electronic equipment and medium

    CN111698088A

  • Data transmission method and related equipment

    CN112751852A

  • Method and system for reciprocally encrypting data, equipment and storage medium

    CN113347144A

  • Distributed storage data processing method and system

    CN115422570A

  • Data storage method and data storage device

    CN115454891A

Cited By

  • Data processing method and device, data storage equipment, storage medium and product

    CN121560953A

  • Method and system for recovering protected file of trusted DCS system, and electronic device, storage medium and computer program product

    WO2026152610A1