An Interplanetary File System Encryption and Decryption Method Based on Slice Optimization
By adopting the encryption and decryption method based on slice optimization in IPFS, using SHA256 and AES256 technologies to encrypt and decrypt file blocks, solving the security problems of IPFS when combining blockchain, and achieving improvements in file security and performance Keep it.
Patent Information
- Application Number
- CN202111647007.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2041-12-30
AI Technical Summary
Interstellar file system (IPFS) has security problems when combined with blockchain, failing to effectively provide access control, resulting in unauthorized data leakage, and existing encryption solutions are complex and affecting system performance.
采用基于切片优化的加解密方法,通过在IPFS中添加可选参数K和k,利用SHA256和AES256加密技术,对文件块进行加密和解密,结合用户设置的加密策略,确保文件安全性,并在不影响性能的情况下保留去重效果。
Improves file security, prevents unauthorized data theft, and maximizes the deduplication effect of IPFS without affecting network performance.
Smart Images

Figure CN114417375B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of IPFS technology and data security, and specifically relates to an interplanetary file system encryption and decryption method based on slice optimization. Background Art
[0002] As the scale of the network continues to expand, the problems brought by centralized systems become more and more serious. Centralized systems are vulnerable to single point failures or external attacks from malicious actors, who may leak data or confidential information. This may lead to adverse effects, especially when user privacy is involved. In addition, high server costs and bandwidth costs also make people more inclined to use distributed data storage systems, so related research directions such as distribution and decentralization have received widespread attention and research.
[0003] Interplanetary File System (IPFS) is one of the most representative distributed data storage systems. However, what makes IPFS a hot topic in research is blockchain. Blockchain uploads data to the public blockchain, which may cause scalability and privacy issues. In fact, it is not advisable to put a lot of data in blockchain transactions because the cost involved is high. In this case, there will be delays when the node needs to download the entire ledger. In addition, the original advantages of blockchain, such as immutability and transparency, will also cause problems when it comes to private data. Therefore, the combination with IPFS is currently a more complete solution.
[0004] IPFS uses many mature technologies, including DHT (distributed hash table), BitTorrent, Git and SFS, and simplifies, modifies and integrates them into a single cohesive system that is more than the sum of its parts. IPFS is widely used in off-chain extended storage due to its smooth integration with current blockchain platforms, which has led to its widespread adoption by many blockchain projects to solve the problem of insufficient on-chain storage space.
[0005] However, IPFS has security issues. It does not provide access control at the connection level to restrict untrusted peers from obtaining unauthorized data, that is, anyone holding the CID can obtain the corresponding content from the network. From a security perspective, there is no completely trustworthy storage node, so the security of the file cannot be solely based on trust in the node.
[0006] Most of the work on IPFS has been devoted to using IPFS as a distributed data storage to develop decentralized applications (DAPP), but has not considered the security of private data. The few papers that address security issues mostly increase file security from the perspective of access control, and only a few attempt to encrypt file objects. However, even so, these solutions have problems such as large workload and complex systems. In addition, this also makes IPFS lose its characteristic attribute of data deduplication. Summary of the invention
[0007] In view of the shortcomings of the above-mentioned existing systems, the present invention proposes an interplanetary file system encryption and decryption method based on slice optimization, which changes the way IPFS handles blocks while retaining all the original IPFS functions and does not affect the deduplication effect or network performance, and provides users with an encryption and decryption solution that increases file security at the cost of slightly increasing workload. This ensures the security of stored data and the efficient use of storage space, and prevents users who provide storage space from stealing other people's data stored locally or other users from obtaining resources without authorization.
[0008] An interplanetary file system encryption and decryption method based on slice optimization specifically includes the following steps:
[0009] Step 1, encrypted upload process: add an optional parameter K to the IPFS ipfs add command to indicate whether encrypted upload is required; if encryption is required, IPFS returns the parameter CID after uploading the file to the IPFS network, and also returns a parameter k as the symmetric encryption key;
[0010] Step 1.1: After the file is sliced by the slicer to obtain several blocks of specified size, first determine whether there is an optional parameter K. If so, proceed to step 1.2. If not, continue with the normal process;
[0011] Step 1.2: Determine whether the current block is the first block. If so, use SHA256 to obtain the hash of the block as the encryption key k;
[0012] Step 1.3: Determine whether the current block needs to be encrypted based on the encryption policy set by the user. If encryption is required, use the key k to perform AES256 encryption, and then construct the DAG and upload it to the IPFS network using the original method for the encrypted or unencrypted file blocks;
[0013] Step 1.4: After the upload is completed, whether the key k is empty determines whether the returned parameter contains the key k; when the key k is empty, only one parameter, namely CIDc, is returned; when the key k is not empty, an additional parameter, namely the key k, is returned;
[0014] Step 2, decryption download process: add an optional parameter k to the ipfs cat command of IPFS to indicate whether decryption download is required; if the file to be obtained this time is uploaded encrypted, the user needs to provide the correct key k to successfully download the file;
[0015] Step 2.1: Determine whether there is an optional parameter k. If so, decrypt the first block and obtain the hash of the decrypted block; if the hash is not equal to the key k provided by the user, it proves that the user did not provide the correct key, the system terminates the process, deletes the downloaded data, and feeds back the result to the user; if the hash is equal to the key k, go to step 2.2, and the block enters the NewDagReader module; if there is no optional parameter k, go to step 2.1, and the block enters the NewDagReader module;
[0016] Step 2.2: Determine whether there is a block larger than 256KB among the blocks obtained in NewDagReader. If so, determine whether there is a key k. If so, decrypt it to obtain a plaintext block of 256KB in size. If not, terminate the process and return a prompt that the password is wrong. Blocks not larger than 256KB are combined into files normally.
[0017] Step 2.3: Return the final combined file to the user.
[0018] Furthermore, in step 1.3, the encryption strategy is to add two properties in the IPFS configuration file config, Encryption_Header encryption header and Encryption_Density encryption density; the encryption header indicates that the first n consecutive blocks of the file must be encrypted, and the encryption density represents how many of the remaining blocks need to be encrypted in addition to the encryption header.
[0019] Furthermore, the default value of the Encryption_Header encryption header is set to 4.
[0020] Furthermore, the default value of the Encryption_Density encryption density is set to 0.01, which means that on average one block is encrypted for every 100 blocks.
[0021] Furthermore, a high priority rule is set in the encryption strategy, and except for the first block, the remaining blocks less than 256KB are not encrypted, that is, only the first block and the blocks with a size of 256KB are encrypted.
[0022] Furthermore, the encryption of the first block adopts the method of ZeroPadding, and the encryption of the remaining blocks of 256KB is performed by padding the end with the key k and then encrypting.
[0023] The beneficial effects achieved by the present invention are as follows: the method can be smoothly integrated into IPFS, and the sliced part of the file blocks are encrypted during the upload process according to the strategy formulated by the user, and the encrypted blocks are identified and decrypted according to the special encryption method during the download process. Through this method, the security of the file can be increased without affecting the performance of IPFS itself, and the deduplication effect of IPFS is retained to the maximum extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is an overview diagram of the effect of the encryption and decryption method described in the embodiment of the present invention.
[0025] Figure 2 It is an overview diagram of uploading the encryption and decryption method described in the embodiment of the present invention.
[0026] Figure 3 It is a download overview diagram of the encryption and decryption method described in the embodiment of the present invention.
[0027] Figure 4 It is an upload flow chart of the encryption and decryption method described in an embodiment of the present invention.
[0028] Figure 5 It is a download flow chart of the encryption and decryption method described in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0030] The Interstellar File System IPFS is being used more and more widely because of its unique advantages and the advantages it brings as a distributed file system. In addition, because it can be smoothly integrated with the current blockchain platform, it is also widely used for off-chain storage expansion. However, IPFS has some privacy issues. Even adding access control to it cannot completely avoid unauthorized access to data by malicious nodes. In response to this problem, the present invention proposes a lightweight encryption scheme based on the characteristics of IPFS file slicing combined with AES256 and SHA256. The scheme can be smoothly integrated into IPFS, and the sliced part of the file blocks are encrypted during the upload process according to the strategy formulated by the user, and the encrypted blocks are identified and decrypted according to a special encryption method during the download process. Through this scheme, the system can increase the security of the file without affecting the performance of IPFS itself, and maximize the deduplication effect of IPFS.
[0031] The effect is summarized as follows: Figure 1 As shown in Figure 2, from a usage perspective, the change to IPFS is to add an optional parameter to the upload and download functions respectively (such as Figure 1As shown in the figure, an optional parameter K is added to the upload function to indicate whether encryption is required. If encryption is required, IPFS will not only return the parameter CID but also a parameter k, the symmetric encryption key, after uploading the file to the IPFS network. The download function adds an optional parameter k. If the file to be obtained is uploaded encrypted, the user needs to provide the correct parameter k to successfully download the file.
[0032] The upload section overview is as follows Figure 2 As shown, during the upload process, the file is first cut into blocks of specified size by the slicer and then input into DAGBuilder in sequence. If the user adds the optional parameter K, the IPFS improved by this method will use the hash of the first cut block as the key k. The hash method uses SHA256, which means that a hash of 256 bits will be generated. Then the 256-bit key k is used as the symmetric encryption key to encrypt the file blocks that need to be encrypted. The encryption method uses AES-256, which is an encryption algorithm that is still sufficient to ensure data security at present. DAG refers to the Merkle directed acyclic graph, a data storage structure. CID is equivalent to the subscript of each node in this graph, but it generally defaults to the subscript of a root node, that is, all the data of the entire file can be found in the DAG through the root node.
[0033] Which file blocks need to be encrypted is mainly determined by two aspects, and this is also the result of taking into account the situation of large files and small files at the same time. Two properties are added to the IPFS configuration file config for users to modify, Encryption_Header encryption header and Encryption_Density encryption density. The encryption header indicates that the first n consecutive blocks of the file must be encrypted. Considering that some small files are still stored in plain text even after cutting, such as txt files, the default value is set to 4, which will ensure that most small files can also be secure. The encryption density represents how many blocks need to be encrypted in addition to the encryption header. Considering the existence of very large files, the default value is set to 0.01 (threshold), which means that on average 1 block is encrypted for every 100 blocks.
[0034] Considering the problem of identifying encrypted blocks during decryption, encryption should have a higher priority rule. Except for the first block, the remaining blocks that are less than 256KB will not be encrypted. This means that this method will only encrypt the first block and blocks of 256KB in size. The encryption of the first block uses the ZeroPadding method. For the encryption of the remaining blocks of 256KB, the encryption is performed after padding the key k at the end to ensure that, except for the first block, the remaining encrypted blocks are larger than 256KB, so as to facilitate identification. And in this case, even if the uploaded user and downloaded user profiles are inconsistent, it will not affect the function.
[0035] Download section overview Figure 3 As shown, since files are stored in the form of file blocks in IPFS, after the user uses the download command, IPFS will obtain each file block in turn according to the DAG that records the file slice information and the distributed hash table that records the storage node information, and finally integrate these blocks into a complete file locally. However, after the upload function is changed, the original download function is no longer applicable. The file blocks in the IPFS network are no longer just plaintext blocks less than or equal to 256KB. Therefore, it is necessary to identify the file blocks during the download process to determine whether they are ciphertext blocks. If so, they need to be decrypted first to obtain the plaintext blocks.
[0036] According to the encryption strategy above, there are two main rules for detecting whether a file block is a ciphertext block. First, blocks larger than 256KB are ciphertext blocks, and second, if the user adds an optional parameter key k, the first block must be a ciphertext block.
[0037] In addition, since there is a possibility of malicious users, we need to consider the case where a malicious user downloads an encrypted file without providing a key or providing an incorrect key. The detection methods for these two cases are as follows: first, a ciphertext block is detected without the user providing the key k; second, the user provides the key k, but it is not equal to the hash after decryption of the first block.
[0038] The present invention provides an interplanetary file system encryption and decryption method based on slice optimization, and the encrypted upload flow chart is as follows: Figure 4 As shown, the download decryption flow chart is as follows Figure 5 The specific steps include the following steps.
[0039] Step 1, encrypted upload process: add an optional parameter K to the IPFS ipfs add command to indicate whether encrypted upload is required; if encryption is required, IPFS will not only return the parameter CID after uploading the file to the IPFS network, but also return a parameter k, the symmetric encryption key.
[0040] Step 1.1: After the file is sliced by the slicer, it will first determine whether there is an optional parameter K. If so, go to step 1.2. If not, continue with the normal process.
[0041] Step 1.2: First determine whether the current block is the first block. If so, use SHA256 to obtain the hash of the block as the encryption key k.
[0042] Step 1.3: Determine whether the current block needs to be encrypted based on the encryption policy set by the user. If encryption is required, use the key k to perform AES256 encryption, and then construct the DAG of the encrypted or unencrypted file blocks in the original way and upload it to the IPFS network.
[0043] Step 1.4: After the upload is completed, whether the key k is empty determines whether the returned parameter contains the key k. When the key k is empty, only one parameter, CIDc, is returned. When the key k is not empty, an additional parameter, key k, is returned.
[0044] Step 2, decryption download process: add an optional parameter k to the IPFS ipfs cat command to indicate whether decryption download is required; if the file to be obtained this time is uploaded encrypted, the user needs to provide the correct key k to successfully download the file.
[0045] Step 2.1: Determine whether there is an optional parameter k. If so, the system will decrypt the first block and obtain the hash of the decrypted block. If the hash is not equal to the key k provided by the user, it proves that the user did not provide the correct key. The system terminates the process, deletes the downloaded data, and feeds back the result to the user. If the hash is equal to the key k, go to step 2.2 and the block enters the NewDagReader module. If there is no optional parameter k, enter the NewDagReader module as usual.
[0046] Step 2.2: Check if there is a block larger than 256KB in the blocks obtained in NewDagReader. If so, determine if there is a key k. If so, decrypt it to obtain a plaintext block of 256KB. If not, terminate the process and return a prompt indicating that the password is wrong. For blocks not larger than 256KB, combine the files normally.
[0047] Step 2.3: Return the final combined file to the user.
[0048] The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiment. Any equivalent modifications or changes made by ordinary technicians in this field based on the contents disclosed by the present invention should be included in the protection scope recorded in the claims.
Claims
1. An interplanetary file system encryption and decryption method based on slice optimization, characterized in that: The method specifically comprises the following steps: Step 1, encrypted upload process: add an optional parameter to the IPFS ipfs add command K To indicate whether encryption is required for upload; if encryption is required, IPFS returns the parameter CID after uploading the file to the IPFS network, and also returns a parameter k And use it as the symmetric encryption key; Step 1.1: After the file is sliced by the slicer to obtain several blocks of specified size, first determine whether there are optional parameters K If yes, go to step 1.2, if no, continue with the normal process; Step 1.2: Determine whether the current block is the first block. If so, use SHA256 to obtain the hash of the block as the encryption key. k ; Step 1.3: Determine whether the current block needs to be encrypted based on the encryption policy set by the user. If encryption is required, use the key k Perform AES256 encryption, then construct DAG with the encrypted or unencrypted file blocks in the original way and upload them to the IPFS network; Step 1.4: After uploading, according to the key k Whether it is empty determines whether the returned parameter contains the key k ; When the key k is empty, only one parameter, namely CIDc, is returned. When the key k is not empty, one more parameter, namely the key k, is returned; Step 2, decryption download process: add an optional parameter to the IPFS ipfs cat command k To indicate whether decryption is required for downloading; if the file to be obtained is uploaded encrypted, the user needs to provide the correct key k To successfully download the file; Step 2.1: Determine if there are optional parameters k If yes, decrypt the first block and get the hash of the decrypted block; if the hash matches the key provided by the user k If they are not equal, it proves that the user has not provided the correct key, the system terminates the process, deletes the downloaded data, and feeds back the result to the user; if the hash is equal to the key k, go to step 2.2 and the block enters the NewDagReader module; if there is no optional parameter k , then go to step 2.1, and the block enters the NewDagReader module; Step 2.2: Determine whether there are blocks larger than 256KB among the blocks obtained in NewDagReader. If so, determine whether there is a key k If there is a plaintext block of 256KB, decrypt it and get it; if not, terminate the process and return a prompt that the password is wrong; if the block is not larger than 256KB, combine the files normally; Step 2.3: Return the final combined file to the user.
2. According to claim 1, the encryption and decryption method of the interplanetary file system based on slice optimization is characterized in that: In step 1.3, the encryption strategy is to add two properties in the IPFS configuration file config, Encryption_Header encryption header and Encryption_Density encryption density; the encryption header indicates that the first n consecutive blocks of the file must be encrypted, and the encryption density represents how many of the remaining blocks need to be encrypted in addition to the encryption header.
3. According to claim 2, the encryption and decryption method of the interplanetary file system based on slice optimization is characterized in that: The default value of the Encryption_Header encryption header is set to 4.
4. The encryption and decryption method of the interplanetary file system based on slice optimization according to claim 2 is characterized in that: The default value of the Encryption_Density encryption density is set to 0.01, which means that on average 1 block is encrypted for every 100 blocks.
5. The encryption and decryption method of the interplanetary file system based on slice optimization according to claim 2 is characterized in that: A high priority rule is set in the encryption strategy. Except for the first block, the remaining blocks less than 256KB are not encrypted, that is, only the first block and the block with a size of 256KB are encrypted.
6. The encryption and decryption method of the interplanetary file system based on slice optimization according to claim 5 is characterized in that: The first block is encrypted using the ZeroPadding method, and the remaining 256KB blocks are encrypted by padding the end with the key k before encryption.
