Decentralized file storage reading method and system
Patent Information
- Application Number
- CN202510551355.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2045-04-29
AI Technical Summary
[0008]本发明实施例中提供一种去中心化文件存储读取方法及系统,以解决现有技术中去中心化存储存在非持久存储,缺乏激励机制、数据的隐私性弱、存储效率低、缺乏访问控制机制的问题
[0021] This invention provides a decentralized file storage and retrieval method and system. The method employs a stateless gateway adaptation layer as the interface layer for users to access the blockchain + IPFS. All file shard CID encrypted data is stored on the blockchain, while the file shard data is stored on IPFS. Users needing to access the platform only need to retrieve the encrypted data from the blockchain, decrypt it locally, and then access the corresponding file on IPFS. By using erasure coding sharding instead of the traditional copy mechanism, high file availability is ensured while significantly improving storage efficiency. Asymmetric encryption technology is used to encrypt the file's CID, and only authorized users can decrypt and access the file, thus guaranteeing data privacy. A real-time monitoring mechanism ensures file accessibility; when the loss of erasure coding shards exceeds a set threshold, shards are retrieved from IPFS, the file is regenerated, and then re-stored, ensuring high reliability of file storage.
Smart Images

Figure CN120469637B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed storage technology, and more specifically, to a decentralized file storage and reading method and system. Background Technology
[0002] Traditional centralized file storage systems (such as cloud storage services) suffer from single points of failure, data privacy breaches, vulnerability to data tampering, and complex file permission management. While decentralized storage networks such as IPFS (InterPlanetary File System) have addressed these issues to some extent, existing IPFS systems still face the following challenges:
[0003] (1) Non-persistent storage and lack of incentive mechanism: IPFS itself is just a content-addressable distributed file system. It does not guarantee that the files you upload will always exist in the network. 1. The local space of the node is limited and the cache may be cleaned up periodically. 2. If no one pins (pins) the files you publish, they may expire quickly. 3. There is no token incentive mechanism to encourage nodes to store your content for a long time.
[0004] (2) Weak data privacy: IPFS's CID (Content Identifier) is generated based on the hash value of the file content. Once the CID is leaked, anyone can access the file content.
[0005] (3) Low storage efficiency: IPFS uses a copy mechanism to improve availability, which leads to low storage efficiency; that is, a file needs to be copied multiple times. If it is a three-backup, the storage efficiency is equivalent to 33.33%.
[0006] (4) Lack of access control mechanism: IPFS itself does not have built-in permission management and access control functions.
[0007] Therefore, there is an urgent need for a new decentralized file storage method and system that combines blockchain technology to solve the above problems. Summary of the Invention
[0008] This invention provides a decentralized file storage and reading method and system to address the problems of non-persistent storage, lack of incentive mechanisms, weak data privacy, low storage efficiency, and lack of access control mechanisms in existing decentralized storage technologies.
[0009] To achieve the above objectives, on the one hand, the present invention provides a decentralized file storage and retrieval method, the method comprising: S1, a gateway receiving a current file uploaded by a current user, and fragmenting the current file according to erasure coding to obtain multiple fragments of the current file; S2, uploading each fragment to the InterPlanetary File System (IPFS) and returning a unique identifier (CID) corresponding to each fragment; S3, performing asymmetric encryption on the unique identifier (CID) corresponding to each fragment using the current user's public key to obtain a first encryption result; uploading the first encryption result to a blockchain; S4, when the current user requests to retrieve the current file, retrieving the first encryption result from the blockchain; decrypting it using the current user's private key to obtain a list of CIDs for the current file;
[0010] S5. Download the corresponding fragments of the current file from the InterPlanetary File System (IPFS) according to the CID list of the current file. Verify the number of downloaded fragments of the current file. If it is less than a first preset threshold, the current file is invalid. Otherwise, restore the current file by using erasure coding on the downloaded fragments of the current file.
[0011] Optionally, the step of fragmenting the current file according to erasure coding to obtain multiple fragments of the current file includes: dividing the current file into k fragments according to erasure coding, and generating m verification fragments according to erasure coding, to obtain k+m fragments of the current file; the first preset threshold is k.
[0012] Optionally, the number of fragments of the current file is periodically checked. If it is less than a second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is then re-fragmented, encrypted, and stored on the blockchain. The second preset threshold is greater than the first preset threshold.
[0013] Optionally, when the user being shared with requests access to the sharing user's current file, the sharing user's gateway retrieves the sharing user's first encrypted result from the blockchain; decrypts it using the sharing user's private key to obtain the CID list of the sharing user's current file; the sharing user's gateway performs asymmetric encryption on the CID list of the sharing user's current file using the public key requested by the user being shared with, obtaining a second encrypted result; uploads the second encrypted result to the blockchain; the sharing user's gateway retrieves the second encrypted result from the blockchain; decrypts it using the sharing user's private key to obtain the CID list of the sharing user's current file; the sharing user's gateway downloads the corresponding fragments of the sharing user's current file from the InterPlanetary File System (IPFS) based on the CID list of the sharing user's current file, verifies the number of downloaded fragments of the sharing user's current file, and if it is less than a first preset threshold, the sharing user's current file is invalid; otherwise, the downloaded fragments of the sharing user's current file are restored using erasure coding to reconstruct the sharing user's current file.
[0014] Optionally, after S2, the method further includes: merging the unique identifiers (CIDs) corresponding to all shards to generate a Merkle tree as the unique identifier of the current file; obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
[0015] On the other hand, the present invention provides a decentralized file storage and retrieval system, comprising: a sharding unit, used for a gateway to receive a current file uploaded by a current user and shard the current file according to erasure coding to obtain multiple shards of the current file; an upload unit, used for uploading each shard to the InterPlanetary File System (IPFS) and returning a unique identifier (CID) corresponding to each shard; an encryption unit, used for asymmetric encryption of the unique identifier (CID) corresponding to each shard using the current user's public key to obtain a first encryption result; and uploading the first encryption result to a blockchain; a decryption unit, used for retrieving the first encryption result from the blockchain when the current user requests to retrieve the current file; and decrypting it using the current user's private key to obtain a list of CIDs for the current file; and a download verification unit, used for downloading the corresponding shards of the current file from the IPFS according to the list of CIDs of the current file, verifying the number of downloaded shards of the current file, and if it is less than a first preset threshold, then the current file is invalid; otherwise, the downloaded shards of the current file are used to recover the current file according to erasure coding.
[0016] Optionally, the step of fragmenting the current file according to erasure coding to obtain multiple fragments of the current file includes: dividing the current file into k fragments according to erasure coding, and generating m verification fragments according to erasure coding, to obtain k+m fragments of the current file; the first preset threshold is k.
[0017] Optionally, the number of fragments of the current file is periodically checked. If it is less than a second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is then re-fragmented, encrypted, and stored on the blockchain. The second preset threshold is greater than the first preset threshold.
[0018] Optionally, when the user being shared with requests access to the sharing user's current file, the sharing user's gateway retrieves the sharing user's first encrypted result from the blockchain; decrypts it using the sharing user's private key to obtain the CID list of the sharing user's current file; the sharing user's gateway performs asymmetric encryption on the CID list of the sharing user's current file using the public key requested by the user being shared with, obtaining a second encrypted result; uploads the second encrypted result to the blockchain; the sharing user's gateway retrieves the second encrypted result from the blockchain; decrypts it using the sharing user's private key to obtain the CID list of the sharing user's current file; the sharing user's gateway downloads the corresponding fragments of the sharing user's current file from the InterPlanetary File System (IPFS) based on the CID list of the sharing user's current file, verifies the number of downloaded fragments of the sharing user's current file, and if it is less than a first preset threshold, the sharing user's current file is invalid; otherwise, the downloaded fragments of the sharing user's current file are restored using erasure coding to reconstruct the sharing user's current file.
[0019] Optionally, it also includes: a merging unit, used to merge all the unique identifiers (CIDs) corresponding to the fragments to generate a Merkle tree as the unique identifier of the current file; obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
[0020] The beneficial effects of this invention are:
[0021] This invention provides a decentralized file storage and retrieval method and system. The method employs a stateless gateway adaptation layer as the interface layer for users to access the blockchain + IPFS. All file shard CID encrypted data is stored on the blockchain, while the file shard data is stored on IPFS. Users needing to access the platform only need to retrieve the encrypted data from the blockchain, decrypt it locally, and then access the corresponding file on IPFS. By using erasure coding sharding instead of the traditional copy mechanism, high file availability is ensured while significantly improving storage efficiency. Asymmetric encryption technology is used to encrypt the file's CID, and only authorized users can decrypt and access the file, thus guaranteeing data privacy. A real-time monitoring mechanism ensures file accessibility; when the loss of erasure coding shards exceeds a set threshold, shards are retrieved from IPFS, the file is regenerated, and then re-stored, ensuring high reliability of file storage. Attached Figure Description
[0022] Figure 1 This is a flowchart of a decentralized file storage and reading method provided in an embodiment of the present invention;
[0023] Figure 2 This is a schematic diagram of a decentralized file storage and retrieval system provided in an embodiment of the present invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0025] Figure 1 This is a flowchart of a decentralized file storage and retrieval method provided by an embodiment of the present invention; as follows: Figure 1 As shown, the method includes:
[0026] S1. The gateway receives the current file uploaded by the current user and segments the current file according to erasure coding to obtain multiple segments of the current file;
[0027] The current user uploads the current file to the gateway. After receiving the file, the gateway first processes it. The gateway first performs verification and preprocessing on the file, such as checking the file format, size, and legality, to ensure that the file meets the upload requirements.
[0028] Then, the current file is fragmented according to erasure coding.
[0029] In an optional implementation, the step of segmenting the current file according to erasure coding to obtain multiple segments of the current file includes:
[0030] The current file is divided into k fragments according to erasure coding, and m verification fragments are generated according to erasure coding to obtain k+m fragments of the current file;
[0031] Erasure coding is used to divide the current file into fragments. Erasure coding is a data encoding method that typically splits the file into multiple data blocks (i.e., k fragments) and check blocks (i.e., m check fragments). The core advantage of erasure coding is that even if some fragments are lost or corrupted, the original file can still be recovered from the remaining fragments and check fragments.
[0032] For example, a file is split into 5 data blocks and 2 parity blocks, i.e., k=5, m=2. Erasure coding allows the entire file content to be recovered from any k data blocks.
[0033] S2. After uploading each fragment to the InterPlanetary File System (IPFS), return the unique identifier (CID) corresponding to each fragment;
[0034] The gateway uploads each shard to the InterPlanetary File System (IPFS). IPFS is a decentralized file storage system that uses content addressing to store each shard of a file across distributed nodes. Each shard's content is assigned a unique hash value, which serves as the shard's unique identifier (CID).
[0035] The InterPlanetary File System (IPFS) returns a unique identifier (CID) for each shard to the gateway.
[0036] In an optional implementation, after S2, the method further includes:
[0037] Merge the unique identifiers (CIDs) corresponding to all fragments to generate a Merkle tree as the unique identifier of the current file;
[0038] Merkle trees are tree-like data structures that can efficiently hash and merge a set of data (such as the CIDs of file fragments) to generate a single hash value, called the root hash.
[0039] Use the root hash as the unique identifier for the current file.
[0040] S3. Encrypt the unique identifier CID corresponding to each shard using the current user's public key to obtain the first encryption result; upload the first encryption result to the blockchain;
[0041] Each fragment's CID will be encrypted using the current user's public key. The encryption process typically uses asymmetric encryption algorithms (such as RSA, ECC, etc.). The purpose of public-key encryption is to ensure that only the user holding the corresponding private key can decrypt and access the file fragment's CID, thus enhancing file access security.
[0042] The encrypted CID is called the first encryption result, which is uploaded to the blockchain. The blockchain is used to record the file's metadata, including the encrypted CID, upload time, owner information, and access control. Due to the immutability of the blockchain, the encrypted CID record stored in the blockchain cannot be tampered with, ensuring file access control and security.
[0043] S4. When the current user requests to obtain the current file, the first encrypted result is obtained from the blockchain; the current user's private key is used to decrypt the result to obtain the CID list of the current file.
[0044] The current user sends a file access request to the gateway. The gateway receives the request and retrieves the first encrypted result (i.e., the encrypted CID corresponding to each shard) from the blockchain. The CID corresponding to each shard stored on the blockchain is encrypted, and only the current user's private key can decrypt the CID corresponding to each shard.
[0045] The gateway uses the current user's private key to decrypt the CID corresponding to each encrypted fragment, obtaining a list of CIDs for the current file. This list contains the unique identifiers (CIDs) for all fragments of the current file. The decryption process ensures that only the user with the private key can access the CIDs of the current file, thus controlling access permissions.
[0046] In an optional implementation, obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
[0047] When a user needs to retrieve the current file, the gateway first obtains the file's unique identifier, the root hash, from the user's request. This unique identifier is unique throughout the entire system and can uniquely correspond to the file.
[0048] The first encrypted result is obtained from the blockchain based on the unique identifier of the current file.
[0049] S5. Download the corresponding fragments of the current file from the InterPlanetary File System (IPFS) according to the CID list of the current file. Verify the number of downloaded fragments of the current file. If it is less than a first preset threshold, the current file is invalid. Otherwise, restore the current file by using erasure coding on the downloaded fragments of the current file.
[0050] The gateway downloads the corresponding file fragments from the IPFS network based on the CID list obtained from the blockchain. Since IPFS is a decentralized storage system, file fragments may be stored on multiple nodes, and the gateway will access multiple nodes to obtain all the necessary fragments.
[0051] The number of fragments of the currently downloaded file is checked to determine if it is less than a first preset threshold (the first preset threshold is k). The first preset threshold is a preset value representing the minimum number of fragments required to recover the current file. If the number of downloaded fragments is less than the first preset threshold, it means that the current file has lost too many fragments and the file cannot be recovered. The gateway will mark the current file as "invalid".
[0052] If the number of downloaded fragments is greater than or equal to a first preset threshold, the gateway will use erasure coding to recover the current file. Erasure coding allows the complete current file to be recovered using a small number of valid fragments and checksum fragments. The recovery process is based on the redundancy information in the erasure coding algorithm, calculating and recovering the lost fragments.
[0053] This invention combines erasure coding, IPFS distributed storage, asymmetric encryption, and blockchain technology to achieve efficient and secure decentralized file storage and access management. By encrypting the file's CID with a public key and uploading the encryption result to the blockchain, access control and privacy protection are ensured. Erasure coding technology allows for file recovery even with lost fragments, providing higher fault tolerance and storage efficiency.
[0054] In one optional implementation, the number of fragments of the current file is periodically checked. If it is less than a second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is then re-fragmented, encrypted, and stored on the blockchain.
[0055] Wherein, the second preset threshold is greater than the first preset threshold.
[0056] In this implementation, the system periodically checks the number of fragments in the current file. This process is automated and aims to ensure the integrity and validity of the file. If some fragments are lost or unavailable in IPFS, the system will be able to detect and address the issue promptly. The periodic check can be set to a fixed time interval (e.g., hourly, daily), or it can be performed under specific triggering conditions (e.g., when a user requests access).
[0057] For example: the number of shards k is 40, the number of verified shards is 20, the second preset threshold is 45, the number of shards of the current file is checked periodically, if it is less than 45, an alarm mechanism is triggered, and the current file is restored by the shards of the current file according to the erasure coding; the current file is then re-sharded, encrypted and stored on the blockchain.
[0058] In one optional implementation,
[0059] When the user whose file is being shared requests to retrieve the current file of the sharing user, the sharing user's gateway retrieves the first encrypted result from the blockchain; it then decrypts the file using the sharing user's private key to obtain the CID list of the current file of the sharing user.
[0060] The gateway of the sharing user performs asymmetric encryption on the CID list of the current file of the sharing user using the public key requested by the sharing user to obtain a second encryption result; and uploads the second encryption result to the blockchain;
[0061] The gateway of the user whose file is being shared retrieves the second encrypted result from the blockchain; it then decrypts the result using the private key of the user whose file is being shared, thus obtaining the CID list of the current file of the sharing user.
[0062] The gateway of the shared user downloads the corresponding fragments of the current file of the sharing user from the InterPlanetary File System (IPFS) based on the CID list of the current file of the sharing user. It verifies the number of downloaded fragments of the current file of the sharing user. If the number is less than a first preset threshold, the current file of the sharing user is invalid. Otherwise, the current file of the sharing user is restored by using erasure coding on the downloaded fragments of the current file of the sharing user.
[0063] For example: User B requests to retrieve User A's current file. User A's gateway first retrieves the first encrypted result stored on the blockchain; the first encrypted result is an encrypted version of the CID list of User A's current file (i.e., asymmetric encryption using User A's public key).
[0064] User A's gateway uses User A's private key to decrypt the first encrypted result obtained from the blockchain; after decryption, the gateway obtains the CID list of User A's current files.
[0065] User A's gateway uses User B's public key to perform asymmetric encryption on the decrypted CID list of User A's current file, resulting in a new second encryption result. Since the CID list is sensitive information, this step ensures that only User B, who holds the private key, can access the file's fragment information. User A's gateway then uploads the second encryption result to the blockchain.
[0066] User B's gateway retrieves a second encrypted result from the blockchain, which is an encrypted version of the CID list of User A's current file. This encrypted result is uploaded to the blockchain via User A's gateway. User B's gateway then decrypts the second encrypted result using User B's private key. After decryption, User B's gateway obtains the CID list of User A's current file.
[0067] User B's gateway downloads the corresponding fragments of User A's current file from IPFS based on the decrypted CID list. The number of downloaded fragments of User A's current file is verified. If it is less than a first preset threshold, User A's current file is invalid; otherwise, the downloaded fragments are used to reconstruct User A's current file using erasure coding.
[0068] This process describes the complete file-sharing workflow, from the sharing user to the shared user, with each step including crucial steps such as encryption, decryption, file download, verification, and recovery. This method combines asymmetric encryption, blockchain storage, IPFS distributed storage, and erasure coding recovery technology to ensure the security, privacy, and integrity of files within a decentralized storage network.
[0069] Figure 2 This is a schematic diagram of the structure of a decentralized file storage and retrieval system provided in an embodiment of the present invention; as shown below. Figure 2 As shown, the system includes:
[0070] Fragmentation unit 201 is used for the gateway to receive the current file uploaded by the current user and to fragment the current file according to erasure coding to obtain multiple fragments of the current file;
[0071] Upload unit 202 is used to upload each fragment to the InterPlanetary File System (IPFS) and then return the unique identifier (CID) corresponding to each fragment;
[0072] The encryption unit 203 is used to perform asymmetric encryption on the unique identifier CID corresponding to each shard using the current user's public key to obtain a first encryption result; and upload the first encryption result to the blockchain.
[0073] The decryption unit 204 is used to obtain the first encrypted result from the blockchain when the current user requests to obtain the current file; and to decrypt it using the current user's private key to obtain the CID list of the current file.
[0074] The download verification unit 205 is used to download the corresponding fragments of the current file from the InterPlanetary File System (IPFS) according to the CID list of the current file, and verify the number of downloaded fragments of the current file. If the number is less than a first preset threshold, the current file is invalid; otherwise, the downloaded fragments of the current file are restored to the current file according to erasure coding.
[0075] In an optional implementation, the step of segmenting the current file according to erasure coding to obtain multiple segments of the current file includes:
[0076] The current file is divided into k fragments according to erasure coding, and m verification fragments are generated according to erasure coding to obtain k+m fragments of the current file;
[0077] The first preset threshold is k.
[0078] In one optional implementation, the number of fragments of the current file is periodically checked. If it is less than a second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is then re-fragmented, encrypted, and stored on the blockchain.
[0079] Wherein, the second preset threshold is greater than the first preset threshold.
[0080] In one optional implementation,
[0081] When the user whose file is being shared requests to retrieve the current file of the sharing user, the sharing user's gateway retrieves the first encrypted result from the blockchain; it then decrypts the file using the sharing user's private key to obtain the CID list of the current file of the sharing user.
[0082] The gateway of the sharing user performs asymmetric encryption on the CID list of the current file of the sharing user using the public key requested by the sharing user to obtain a second encryption result; and uploads the second encryption result to the blockchain;
[0083] The gateway of the user whose file is being shared retrieves the second encrypted result from the blockchain; it then decrypts the result using the private key of the user whose file is being shared, thus obtaining the CID list of the current file of the sharing user.
[0084] The gateway of the shared user downloads the corresponding fragments of the current file of the sharing user from the InterPlanetary File System (IPFS) based on the CID list of the current file of the sharing user. It verifies the number of downloaded fragments of the current file of the sharing user. If the number is less than a first preset threshold, the current file of the sharing user is invalid. Otherwise, the current file of the sharing user is restored by using erasure coding on the downloaded fragments of the current file of the sharing user.
[0085] In an optional implementation, it further includes:
[0086] The merge unit is used to merge the unique identifiers (CIDs) corresponding to all fragments to generate a Merkle tree as the unique identifier of the current file.
[0087] The step of obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
[0088] The system of the present invention corresponds to the method described above, and the specific implementation of the system will not be repeated here.
[0089] The beneficial effects of this invention are:
[0090] This invention provides a decentralized file storage and retrieval method and system. The method employs a stateless gateway adaptation layer as the interface layer for users to access the blockchain + IPFS. All file shard CID encrypted data is stored on the blockchain, while the file shard data is stored on IPFS. Users needing to access the platform only need to retrieve the encrypted data from the blockchain, decrypt it locally, and then access the corresponding file on IPFS. By using erasure coding sharding instead of the traditional copy mechanism, high file availability is ensured while significantly improving storage efficiency. Asymmetric encryption technology is used to encrypt the file's CID, and only authorized users can decrypt and access the file, thus guaranteeing data privacy. A real-time monitoring mechanism ensures file accessibility; when the loss of erasure coding shards exceeds a set threshold, shards are retrieved from IPFS, the file is regenerated, and then re-stored, ensuring high reliability of file storage.
[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A decentralized file storage and retrieval method, characterized in that, include: S1. The gateway receives the current file uploaded by the current user and segments the current file according to erasure coding to obtain multiple segments of the current file; S2. After uploading each fragment to the InterPlanetary File System (IPFS), return the unique identifier (CID) corresponding to each fragment; S3. Encrypt the unique identifier CID corresponding to each shard using the current user's public key to obtain the first encryption result; upload the first encryption result to the blockchain; S4. When the current user requests to obtain the current file, the first encrypted result is obtained from the blockchain; the current user's private key is used to decrypt the result to obtain the CID list of the current file. S5. Download the corresponding fragments of the current file from the InterPlanetary File System (IPFS) according to the CID list of the current file. Verify the number of fragments of the current file downloaded. If it is less than the first preset threshold, the current file is invalid. Otherwise, restore the current file by using erasure coding on the downloaded fragments of the current file. When the user whose file is being shared requests to retrieve the current file of the sharing user, the sharing user's gateway retrieves the first encrypted result from the blockchain; it then decrypts the file using the sharing user's private key to obtain the CID list of the current file of the sharing user. The gateway of the sharing user performs asymmetric encryption on the CID list of the current file of the sharing user using the public key requested by the sharing user, and obtains a second encryption result; Upload the second encryption result to the blockchain; The gateway of the user being shared with obtains the second encrypted result from the blockchain; Decrypt using the private key of the user whose file is being shared to obtain the CID list of the current file of the sharing user; The gateway of the shared user downloads the corresponding fragments of the current file of the sharing user from the InterPlanetary File System (IPFS) based on the CID list of the current file of the sharing user. It verifies the number of downloaded fragments of the current file of the sharing user. If the number is less than a first preset threshold, the current file of the sharing user is invalid. Otherwise, the current file of the sharing user is restored by using erasure coding on the downloaded fragments of the current file of the sharing user.
2. The method according to claim 1, characterized in that, The step of dividing the current file into fragments based on erasure coding to obtain multiple fragments of the current file includes: The current file is divided into k fragments according to erasure coding, and m verification fragments are generated according to erasure coding to obtain k+m fragments of the current file; The first preset threshold is k.
3. The method according to claim 1, characterized in that: The number of fragments of the current file is checked periodically. If it is less than the second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is re-sharded, encrypted, and stored on the blockchain; Wherein, the second preset threshold is greater than the first preset threshold.
4. The method according to claim 1, characterized in that, Following S2, it also includes: Merge the unique identifiers (CIDs) corresponding to all fragments to generate a Merkle tree as the unique identifier of the current file; The step of obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
5. A decentralized file storage and retrieval system, characterized in that, include: The fragmentation unit is used by the gateway to receive the current file uploaded by the current user and to fragment the current file according to erasure coding to obtain multiple fragments of the current file; The upload unit is used to upload each fragment to the InterPlanetary File System (IPFS) and return the unique identifier (CID) corresponding to each fragment. The encryption unit is used to perform asymmetric encryption on the unique identifier CID corresponding to each fragment using the current user's public key to obtain the first encryption result; Upload the first encryption result to the blockchain; The decryption unit is used to retrieve the first encrypted result from the blockchain when the current user requests to obtain the current file; and to decrypt it using the current user's private key to obtain the CID list of the current file. The download verification unit is used to download the corresponding fragments of the current file from the InterPlanetary File System (IPFS) according to the CID list of the current file, and verify the number of downloaded fragments of the current file. If the number is less than a first preset threshold, the current file is invalid; otherwise, the downloaded fragments of the current file are used to restore the current file using erasure coding. When the user whose file is being shared requests to retrieve the current file of the sharing user, the sharing user's gateway retrieves the first encrypted result from the blockchain; it then decrypts the file using the sharing user's private key to obtain the CID list of the current file of the sharing user. The gateway of the sharing user performs asymmetric encryption on the CID list of the current file of the sharing user using the public key requested by the sharing user, and obtains a second encryption result; Upload the second encryption result to the blockchain; The gateway of the user being shared with obtains the second encrypted result from the blockchain; Decrypt using the private key of the user whose file is being shared to obtain the CID list of the current file of the sharing user; The gateway of the shared user downloads the corresponding fragments of the current file of the sharing user from the InterPlanetary File System (IPFS) based on the CID list of the current file of the sharing user. It verifies the number of downloaded fragments of the current file of the sharing user. If the number is less than a first preset threshold, the current file of the sharing user is invalid. Otherwise, the current file of the sharing user is restored by using erasure coding on the downloaded fragments of the current file of the sharing user.
6. The system according to claim 5, characterized in that, The step of dividing the current file into fragments based on erasure coding to obtain multiple fragments of the current file includes: The current file is divided into k fragments according to erasure coding, and m verification fragments are generated according to erasure coding to obtain k+m fragments of the current file; The first preset threshold is k.
7. The system according to claim 5, characterized in that: The number of fragments of the current file is checked periodically. If it is less than the second preset threshold, an alarm mechanism is triggered, and the fragments of the current file are restored to the current file according to erasure coding. The current file is re-sharded, encrypted, and stored on the blockchain; Wherein, the second preset threshold is greater than the first preset threshold.
8. The system according to claim 5, characterized in that, Also includes: The merge unit is used to merge the unique identifiers (CIDs) corresponding to all fragments to generate a Merkle tree as the unique identifier of the current file. The step of obtaining the first encryption result from the blockchain includes: obtaining the first encryption result from the blockchain based on the unique identifier of the current file.
Citation Information
Patent Citations
Object storage caching method based on IPFS technology
CN117743278A
Decentralized information safe and efficient storage and sharing method supporting data verification
CN119690930A