Summary of the invention
In view of this, the present invention proposes a kind of metadata validation method, block chain node device and computer-readable storage
Medium, to improve the safety of metadata write-in.
Firstly, to achieve the above object, the present invention proposes a kind of metadata validation method, which comprises
Server receives the metadata for the file that user terminal uploads, and the metadata includes multiple data with the file
Traceable node Hash list in the Merkel tree of block construction;
Server calculates the root cryptographic Hash of the Merkel tree according to the traceable node Hash list;
Server judges whether described cryptographic Hash be identical as the cryptographic Hash of the file, if identical, determines the member
Data verification passes through, and saves the metadata.
Preferably, the preservation metadata includes:
Block chain is written in the metadata by server.
Preferably, before the metadata that the server receives that user terminal uploads, this method further include:
The file is cut into the data block of the first preset quantity by user terminal according to predetermined segmentation rules;
User terminal calculates corresponding first cryptographic Hash of each data block using predetermined hash algorithm, according to described
One cryptographic Hash and predetermined Merkel tree construction rule building Merkel tree.
Preferably, the predetermined segmentation rules include:
The data file is cut into the data block of identical first preset quantity of size of data;Alternatively,
First preset quantity is denoted as M, when M is the natural number more than or equal to 2, according to predetermined file
The mapping relations of magnitude range and cutting data block size determine the data block size that data file described in cutting obtains, according to
The character sequence of determining the data block size and the data file, data file described in cutting obtain the identical M- of size
1 data block, remaining after cutting is m-th data block.
Preferably, the predetermined Merkel tree construction rule includes:
Using each first cryptographic Hash as the most junior Hash value node of the Merkel tree;
Each first cryptographic Hash is grouped according to predetermined rule of classification to obtain several the first groupings,
For all first cryptographic Hash in each first grouping, one corresponding second is calculated using predetermined hash algorithm
Cryptographic Hash;
For the N cryptographic Hash being calculated, N is the natural number more than or equal to 2, and circulation executes following steps: working as institute
State N cryptographic Hash quantity only one when terminate cryptographic Hash calculating, most using the N cryptographic Hash as the Merkel tree
Higher level's Hash value node;Alternatively, when the quantity of the N cryptographic Hash has multiple, using each N cryptographic Hash as the Merck
The N grades of Hash value nodes reciprocal of your tree, if being grouped to obtain to all N cryptographic Hash according to predetermined rule of classification
Dry N grouping calculates a correspondence using predetermined hash algorithm for the N cryptographic Hash in each N grouping
N+1 cryptographic Hash.
Preferably, the predetermined rule of classification includes:
First grouping: the data block of cutting is ranked up according to the character sequence of the data file to be slit, root
Putting in order to be ranked up to obtain by corresponding first cryptographic Hash of each data block and breathed out by all first according to each data block
The first set of uncommon value composition, the first cryptographic Hash of the second preset quantity is selected according to collating sequence every time from the first set
It is grouped as one first, until the quantity of the first cryptographic Hash remaining in the first set is less than second present count
Amount is then grouped the first cryptographic Hash remaining in the first set as one first, terminates the first grouping process;
V grouping, V are more than or equal to 2 natural number: according to putting in order to V Hash for each -1 cryptographic Hash of V
Value is ranked up to obtain the V set being made of all V cryptographic Hash, selects every time from the V set according to collating sequence
The V cryptographic Hash of second preset quantity is grouped as a V, until the quantity of V cryptographic Hash remaining in the V set
Less than second preset quantity, then V cryptographic Hash work remaining in the V set is divided into a V grouping, terminated
V is grouped process.
In addition, to achieve the above object, the present invention also proposes a kind of metadata validation system, the system comprises mutually it
Between the server and user terminal that communicate to connect, the server is used for:
The metadata for the file that user terminal uploads is received, the metadata includes constructing with multiple data blocks of the file
Merkel tree in traceable node Hash list;
The root cryptographic Hash of the Merkel tree is calculated according to the traceable node Hash list;
Judge whether described cryptographic Hash be identical as the cryptographic Hash of the file, if identical, determines that the metadata is tested
Card passes through, and saves the metadata.
Preferably, the server is also used to:
Block chain is written into the metadata.
Preferably, the user terminal is used for:
The file is cut into the data block of the first preset quantity according to predetermined segmentation rules;
Corresponding first cryptographic Hash of each data block is calculated using predetermined hash algorithm, according to first Hash
Value and predetermined Merkel tree construction rule building Merkel tree.
Preferably, the predetermined segmentation rules include:
The data file is cut into the data block of identical first preset quantity of size of data;Alternatively,
First preset quantity is denoted as M, when M is the natural number more than or equal to 2, according to predetermined file
The mapping relations of magnitude range and cutting data block size determine the data block size that data file described in cutting obtains, according to
The character sequence of determining the data block size and the data file, data file described in cutting obtain the identical M- of size
1 data block, remaining after cutting is m-th data block.
Preferably, the predetermined Merkel tree construction rule includes:
Using each first cryptographic Hash as the most junior Hash value node of the Merkel tree;
Each first cryptographic Hash is grouped according to predetermined rule of classification to obtain several the first groupings,
For all first cryptographic Hash in each first grouping, one corresponding second is calculated using predetermined hash algorithm
Cryptographic Hash;
For the N cryptographic Hash being calculated, N is the natural number more than or equal to 2, and circulation executes following steps: working as institute
State N cryptographic Hash quantity only one when terminate cryptographic Hash calculating, most using the N cryptographic Hash as the Merkel tree
Higher level's Hash value node;Alternatively, when the quantity of the N cryptographic Hash has multiple, using each N cryptographic Hash as the Merck
The N grades of Hash value nodes reciprocal of your tree, if being grouped to obtain to all N cryptographic Hash according to predetermined rule of classification
Dry N grouping calculates a correspondence using predetermined hash algorithm for the N cryptographic Hash in each N grouping
N+1 cryptographic Hash.
Preferably, the predetermined rule of classification includes:
First grouping: the data block of cutting is ranked up according to the character sequence of the data file to be slit, root
Putting in order to be ranked up to obtain by corresponding first cryptographic Hash of each data block and breathed out by all first according to each data block
The first set of uncommon value composition, the first cryptographic Hash of the second preset quantity is selected according to collating sequence every time from the first set
It is grouped as one first, until the quantity of the first cryptographic Hash remaining in the first set is less than second present count
Amount is then grouped the first cryptographic Hash remaining in the first set as one first, terminates the first grouping process.
V grouping, V are more than or equal to 2 natural number: according to putting in order to V Hash for each -1 cryptographic Hash of V
Value is ranked up to obtain the V set being made of all V cryptographic Hash, selects every time from the V set according to collating sequence
The V cryptographic Hash of second preset quantity is grouped as a V, until the quantity of V cryptographic Hash remaining in the V set
Less than second preset quantity, then V cryptographic Hash work remaining in the V set is divided into a V grouping, terminated
V is grouped process.
In addition, to achieve the above object, the present invention also proposes that a kind of server, the server include memory and processing
Device is stored with metadata validation program on the memory, when the processor executes the metadata validation program, realizes such as
Lower method:
The metadata for the file that user terminal uploads is received, the metadata includes constructing with multiple data blocks of the file
Merkel tree in traceable node Hash list;
The root cryptographic Hash of the Merkel tree is calculated according to the traceable node Hash list;
Judge whether described cryptographic Hash be identical as the cryptographic Hash of the file, if identical, determines that the metadata is tested
Card passes through, and saves the metadata.
Preferably, the preservation metadata includes:
Block chain is written into the metadata.
In addition, to achieve the above object, the present invention also proposes a kind of computer readable storage medium, described computer-readable
Storage medium is stored with metadata validation program, and the metadata validation program can be executed by least one processor, to realize
Following method:
The metadata for the file that user terminal uploads is received, the metadata includes constructing with multiple data blocks of the file
Merkel tree in traceable node Hash list;
The root cryptographic Hash of the Merkel tree is calculated according to the traceable node Hash list;
Judge whether described cryptographic Hash be identical as the cryptographic Hash of the file, if identical, determines that the metadata is tested
Card passes through, and saves the metadata.
Server of the present invention receives the metadata for the file that user terminal uploads, and the metadata includes with the more of the file
Traceable node Hash list in the Merkel tree of a data block construction;Server is according to the traceable node Hash list
Calculate the root cryptographic Hash of the Merkel tree;Server judges whether described cryptographic Hash be identical as the cryptographic Hash of the file,
If identical, determine that the metadata validation passes through, and save the metadata.Compared to the prior art, the present invention improves
The safety of block chain data write-in, prevents rogue attacks person from gathering around using the metadata of loophole data falsification file and tampering with a document
The person of having, so that the leakage of non-public file is caused, alternatively, invalid data is caused to build consensus in block chain.
Specific embodiment
The principle and features of the present invention will be described below with reference to the accompanying drawings, and the given examples are served only to explain the present invention, and
It is non-to be used to limit the scope of the invention.
It should be noted that the description for being related to " first ", " second " etc. in the present invention is used for description purposes only, and cannot
It is interpreted as its relative importance of indication or suggestion or implicitly indicates the quantity of indicated technical characteristic.Define as a result, " the
One ", the feature of " second " can explicitly or implicitly include at least one described feature.In addition, between each embodiment
Technical solution can be combined with each other, but must based on can be realized by those of ordinary skill in the art, work as technical solution
Combination there is conflicting or cannot achieve when and will be understood that the combination of this technical solution is not present, also do not wanted in the present invention
Within the protection scope asked.
The present invention proposes a kind of metadata validation system.
Referring to Fig. 1, Fig. 1 is the system architecture diagram of one embodiment of metadata validation system of the present invention.
In the present embodiment, the metadata validation system includes the server 1 and user terminal communicated to connect between each other
2, the server 1 is used for:
The metadata for the file that user terminal 2 uploads is received, the metadata includes multiple data block structures with the file
Traceable node Hash list in the Merkel tree made;
The root cryptographic Hash of the Merkel tree is calculated according to the traceable node Hash list;
Judge whether described cryptographic Hash be identical as the cryptographic Hash of the file, if identical, determines that the metadata is tested
Card passes through, and saves the metadata, for example, block chain is written in the metadata.
The metadata is to be used to indicate to have stored or the file information of file to be stored.The metadata includes with institute
State file multiple data blocks construction Merkel tree in traceable node Hash list, wherein the Merkel tree in advance by
User terminal 2 is formed using file build, and the structure of the Merkel tree can refer to Fig. 5, in Fig. 5, box B1, B2 of most junior, B3,
B4, B5, B6, B7, B8 represent the first preset quantity data block, and except the data block of row last, each box of remaining row is represented
One Merkel's tree node.User terminal 2 selects several nodes as traceable section from multiple nodes of Merkel tree in advance
Point, for example, Fig. 5 interior joint H1, H2, H34 and H5678 can be chosen as traceable node, and according to the Hash of four nodes
Value generates traceable node Hash list.When choosing traceable node it is noted that the cryptographic Hash of traceable node should
It is several cryptographic Hash that the root cryptographic Hash of the Merkel tree can be obtained by calculation.It is also optional according to specific application scenarios
Take Fig. 5 interior joint H3, H4, H12 and H1234 as traceable node, this is not limited by the present invention.
If traceable node is Fig. 5 interior joint H1, H2, H34 and H5678, server 1 is first by the Kazakhstan of node H1 and H2
Uncommon value is spliced, then the cryptographic Hash (H1+H2) that splicing is obtained carries out Hash operation (as utilized predetermined hash algorithm
Hash operation is carried out, predetermined hash algorithm includes MD5, SHA1 etc.), obtain the cryptographic Hash of node H12.Then, it will save
The cryptographic Hash of point H12 and H34 is spliced, and the cryptographic Hash (H12+H34) that splicing is obtained carries out Hash operation, obtains node
The cryptographic Hash of H1234.Finally, the cryptographic Hash of node H1234 and H5678 are spliced, the cryptographic Hash that splicing is obtained
(H1234+H5678) Hash operation is carried out, the root cryptographic Hash of root node is obtained.
The cryptographic Hash of above-mentioned file can be obtained and be uploaded to file progress Hash operation by user terminal 2, can also be by server 1
It carries out Hash operation to file to obtain, alternatively, the cryptographic Hash of file can also be calculated simultaneously by other any applicable devices
It is uploaded to server 1, this is not limited by the present invention.
In the case where metadata is not tampered with or is forged, by the way that the root Hash that is calculated of node Hash list can be traced
Value should be identical as the cryptographic Hash of file, therefore, when server 1 determines that root cryptographic Hash is identical as the cryptographic Hash of file, it is believed that
The metadata validation passes through, which is saved.When server 1 determines that root cryptographic Hash is different from the cryptographic Hash of file
When, it is believed that metadata validation failure, the metadata are tampered or forge, and refuse the meta-data preservation.
The present embodiment server 1 receives the metadata for the file that user terminal 2 uploads, and the metadata includes with the file
Multiple data blocks construction Merkel tree in traceable node Hash list;Server 1 is breathed out according to the traceable node
Uncommon list calculates the root cryptographic Hash of the Merkel tree;Server 1 judge described cryptographic Hash whether the Hash with the file
It is worth identical, if identical, determines that the metadata validation passes through, and save the metadata.Compared to the prior art, this implementation
Example improves the safety of block chain data write-in, prevents rogue attacks person using the metadata of loophole data falsification file and usurps
Change file owner, so that the leakage of non-public file is caused, alternatively, invalid data is caused to build consensus in block chain.
Further, in the present embodiment, user terminal 2 is used for:
The file is cut into the data block of the first preset quantity (for example, Fig. 5 institute according to predetermined segmentation rules
8 data blocks B1, B2, B3, B4, B5, B6, B7, the B8 shown.), and each data block is calculated using predetermined hash algorithm
Corresponding first cryptographic Hash, according to first cryptographic Hash and predetermined Merkel tree construction rule building Merkel tree.
The predetermined segmentation rules include:
The data file is cut into the data block of identical first preset quantity of size of data;Alternatively,
First preset quantity is denoted as M, when M is the natural number more than or equal to 2, according to predetermined file
The mapping relations of magnitude range and cutting data block size determine the data block size that data file described in cutting obtains, according to
The character sequence of determining the data block size and the data file, data file described in cutting obtain the identical M- of size
1 data block, remaining after cutting is m-th data block.M data block size is different from M-1 data block size.
For example, the predetermined hash algorithm has MD5, SHA1 etc..The predetermined Merkel tree construction rule
Then include:
Using each first cryptographic Hash as the most junior Hash value node of Merkel tree;
Each first cryptographic Hash is grouped according to predetermined rule of classification to obtain several the first groupings, for
All first cryptographic Hash in each first grouping, calculate corresponding second Hash using predetermined hash algorithm
Value;
For the N cryptographic Hash being calculated, N is the natural number more than or equal to 2, and circulation executes following steps: described
The quantity of N cryptographic Hash only one when terminate cryptographic Hash calculating, using N cryptographic Hash as the most higher level cryptographic Hash of Merkel tree
Node;Alternatively, when the quantity of the N cryptographic Hash has multiple, using each N cryptographic Hash as the inverse of the Merkel tree
N grades of Hash value nodes are grouped all N cryptographic Hash according to predetermined rule of classification to obtain several N points
Group calculates a corresponding N+1 using predetermined hash algorithm and breathes out for the N cryptographic Hash in each N grouping
Uncommon value.
Predetermined rule of classification includes the first rule of classification and V rule of classification, and wherein V is more than or equal to 2
Natural number.
First rule of classification includes:
The data block of cutting is ranked up according to the character sequence of the data file to be slit, according to described each
Corresponding first cryptographic Hash of each data block is ranked up to obtain by the putting in order of data block to be made of all first cryptographic Hash
First set selects the first cryptographic Hash of the second preset quantity as one every time according to collating sequence from the first set
One grouping then will be described until the quantity of the first cryptographic Hash remaining in the first set is less than second preset quantity
Remaining first cryptographic Hash is grouped as one first in first set, terminates the first grouping process.
For example, the collating sequence of 8 data blocks shown in fig. 5 is B1, B2, B3, B4, B5, B6, B7, B8, then this 8 numbers
Collating sequence according to corresponding first cryptographic Hash of block is H1 (B1), H2 (B2), H3 (B3), H4 (B4), H5 (B5), H6 (B6), H7
(B7),H8(B8).H1 (B1), H2 (B2) in Fig. 5 are one first grouping.Second preset quantity and the first preset quantity can
With identical, can also be different, the second preset quantity can be 2.
V rule of classification, V are more than or equal to 2 natural number: according to putting in order to V for each -1 cryptographic Hash of V
Cryptographic Hash is ranked up to obtain the V set being made of all V cryptographic Hash, each from the V set according to collating sequence
The V cryptographic Hash of the second preset quantity is selected to be grouped as a V, until V cryptographic Hash remaining in the V set
Quantity is less than second preset quantity, then V cryptographic Hash work remaining in the V set is divided into a V grouping,
Terminate V and is grouped process.For example, the second cryptographic Hash H12 (H1+H2), the second cryptographic Hash H34 (H3+H4) in Fig. 5 are one
Second packet.
The present invention proposes a kind of server.
Referring to Fig. 2, Fig. 2 is the schematic diagram of 1 one embodiment of server of the present invention.
In the present embodiment, metadata validation program 10 is installed and is run in server 1.The server 1 includes, but
It is not limited to, the memory 11 and processor 12 of connection is in communication with each other by program bus.Fig. 1 is illustrated only with component 11-12
Block chain node device 1, it should be understood that being not required for implementing all components shown, the implementation that can be substituted is more
More or less component.
Memory 11 can be the internal storage unit of block chain node device 1, such as the clothes in some embodiments
The hard disk or memory of business device 1.Memory 11 is also possible to the External memory equipment of server 1 in further embodiments, such as
The plug-in type hard disk being equipped on server 1, intelligent memory card (Smart Media Card, SMC), secure digital (Secure
Digital, SD) card, flash card (Flash Card) etc..Further, memory 11 can also include that the inside of server 1 is deposited
Storage unit and External memory equipment.Memory 11 is for storing the application software and Various types of data for being installed on server 1, such as member
The program code etc. of data verifying program 10.Memory 11, which can be also used for temporarily storing, have been exported or will export
Data.
Processor 12 can be in some embodiments a central processing unit (Central Processing Unit,
CPU), microprocessor or other data processing chips, program code or processing data for being stored in run memory 11, example
Such as execute metadata validation program 10.
The present invention proposes a kind of metadata validation program.
Referring to Fig. 3, Fig. 3 is the Program modual graph of 10 1 embodiment of metadata validation program in Fig. 2.In the present embodiment
In, metadata validation program 10 can be divided into one or more modules, one or more module is stored in memory
In 11, and it is performed by one or more processors (the present embodiment is processor 12), to complete the present invention.For example, in Fig. 2
In, metadata validation program 10 can be divided into receiving module 101, computing module 102, judgment module 103.Alleged by the present invention
Module be refer to complete specific function series of computation machine program instruction section, tested than program more suitable for descriptive metadata
Demonstrate,prove the implementation procedure of program 10 in the server 1, in which:
Receiving module 101, the metadata of the file for receiving the upload of user terminal 2, the metadata includes with the text
Traceable node Hash list in the Merkel tree of multiple data blocks construction of part.
The metadata is to be used to indicate to have stored or the file information of file to be stored.The metadata includes with institute
State file multiple data blocks construction Merkel tree in traceable node Hash list, wherein the Merkel tree in advance by
User terminal 2 is formed using file build, and the structure of the Merkel tree can refer to Fig. 5, in Fig. 5, box B1, B2 of most junior, B3,
B4, B5, B6, B7, B8 represent the first preset quantity data block, and except the data block of row last, each box of remaining row is represented
One Merkel's tree node.User terminal 2 selects several nodes as traceable section from multiple nodes of Merkel tree in advance
Point, for example, Fig. 5 interior joint H1, H2, H34 and H5678 can be chosen as traceable node, and according to the Hash of four nodes
Value generates traceable node Hash list.When choosing traceable node it is noted that the cryptographic Hash of traceable node should
It is several cryptographic Hash that the root cryptographic Hash of the Merkel tree can be obtained by calculation.It is also optional according to specific application scenarios
Take Fig. 5 interior joint H3, H4, H12 and H1234 as traceable node, this is not limited by the present invention.
Computing module 102, for calculating the root cryptographic Hash of the Merkel tree according to the traceable node Hash list.
For example, if traceable node is Fig. 5 interior joint H1, H2, H34 and H5678, first by the Hash of node H1 and H2
Value is spliced, then will the obtained cryptographic Hash (H1+H2) of splicing carry out Hash operation (as using predetermined hash algorithm into
Row Hash operation, predetermined hash algorithm include MD5, SHA1 etc.), obtain the cryptographic Hash of node H12.Then, by node
The cryptographic Hash of H12 and H34 is spliced, and the cryptographic Hash (H12+H34) that splicing is obtained carries out Hash operation, obtains node
The cryptographic Hash of H1234.Finally, the cryptographic Hash of node H1234 and H5678 are spliced, the cryptographic Hash that splicing is obtained
(H1234+H5678) Hash operation is carried out, the root cryptographic Hash of root node is obtained.
The cryptographic Hash of above-mentioned file can be obtained and be uploaded to file progress Hash operation by user terminal 2, can also be by calculating mould
Block 102 carries out Hash operation to file and obtains, alternatively, the cryptographic Hash of file can also be by other any applicable device meters
Server 1 is calculated and is uploaded to, this is not limited by the present invention.Judgment module 103, for judge described cryptographic Hash whether with institute
The cryptographic Hash for stating file is identical, if identical, determines that the metadata validation passes through, and save the metadata (for example, by first
Data are saved into block chain).
In the case where metadata is not tampered with or is forged, by the way that the root Hash that is calculated of node Hash list can be traced
Value should be identical as the cryptographic Hash of file, therefore, when judgment module 103 determines that root cryptographic Hash is identical as the cryptographic Hash of file,
Think that the metadata validation passes through, which is saved.When judgment module 103 determines the Hash of root cryptographic Hash and file
When being worth different, it is believed that metadata validation failure, the metadata are tampered or forge, and refuse the meta-data preservation.
The present embodiment server 1 receives the metadata for the file that user terminal 2 uploads, and the metadata includes with the file
Multiple data blocks construction Merkel tree in traceable node Hash list;According to the traceable node Hash list meter
Calculate the root cryptographic Hash of the Merkel tree;Server 1 judges whether described cryptographic Hash be identical as the cryptographic Hash of the file, such as
Fruit is identical, determines that the metadata validation passes through, and save the metadata.Compared to the prior art, embodiment improves
The safety of block chain data write-in, prevents rogue attacks person from gathering around using the metadata of loophole data falsification file and tampering with a document
The person of having, so that the leakage of non-public file is caused, alternatively, invalid data is caused to build consensus in block chain.
Further, the present invention also proposes that a kind of computer readable storage medium, the computer readable storage medium are deposited
Metadata validation program 10 is contained, the method that the metadata validation program 10 is realized when being executed by least one processor please join
According to the description in above-described embodiment.
Further it is proposed that a kind of metadata validation method.
Referring to Fig. 4, Fig. 4 is the flow chart of one embodiment of metadata validation method of the present invention.
In the present embodiment, which comprises
S10, server 1 receive the metadata for the file that user terminal 2 uploads, and the metadata includes with the more of the file
Traceable node Hash list in the Merkel tree of a data block construction.
The metadata is to be used to indicate to have stored or the file information of file to be stored.The metadata includes with institute
State file multiple data blocks construction Merkel tree in traceable node Hash list, wherein the Merkel tree in advance by
User terminal 2 is formed using file build, and the structure of the Merkel tree can refer to Fig. 5, in Fig. 5, box B1, B2 of most junior, B3,
B4, B5, B6, B7, B8 represent the first preset quantity data block, and except the data block of row last, each box of remaining row is represented
One Merkel's tree node.User terminal 2 selects several nodes as traceable section from multiple nodes of Merkel tree in advance
Point, for example, Fig. 5 interior joint H1, H2, H34 and H5678 can be chosen as traceable node, and according to the Hash of four nodes
Value generates traceable node Hash list.When choosing traceable node it is noted that the cryptographic Hash of traceable node should
It is several cryptographic Hash that the root cryptographic Hash of the Merkel tree can be obtained by calculation.It is also optional according to specific application scenarios
Take Fig. 5 interior joint H3, H4, H12 and H1234 as traceable node, this is not limited by the present invention.
S20, server 1 calculate the root cryptographic Hash of the Merkel tree according to the traceable node Hash list.
For example, if traceable node is Fig. 5 interior joint H1, H2, H34 and H5678, first by the Hash of node H1 and H2
Value is spliced, then will the obtained cryptographic Hash (H1+H2) of splicing carry out Hash operation (as using predetermined hash algorithm into
Row Hash operation, predetermined hash algorithm include MD5, SHA1 etc.), obtain the cryptographic Hash of node H12.Then, by node
The cryptographic Hash of H12 and H34 is spliced, and the cryptographic Hash (H12+H34) that splicing is obtained carries out Hash operation, obtains node
The cryptographic Hash of H1234.Finally, the cryptographic Hash of node H1234 and H5678 are spliced, the cryptographic Hash that splicing is obtained
(H1234+H5678) Hash operation is carried out, the root cryptographic Hash of root node is obtained.
The cryptographic Hash of above-mentioned file can be obtained and be uploaded to file progress Hash operation by user terminal 2, can also be by server 1
It carries out Hash operation to file to obtain, alternatively, the cryptographic Hash of file can also be calculated simultaneously by other any applicable devices
It is uploaded to server 1, this is not limited by the present invention.S30, server 1 judge described cryptographic Hash whether with the file
Cryptographic Hash is identical, if identical, determines that the metadata validation passes through, and save the metadata (for example, by meta-data preservation
Into block chain).
In the case where metadata is not tampered with or is forged, by the way that the root Hash that is calculated of node Hash list can be traced
Value should be identical as the cryptographic Hash of file, therefore, when server 1 determines that root cryptographic Hash is identical as the cryptographic Hash of file, it is believed that
The metadata validation passes through, which is saved.When server 1 determines that root cryptographic Hash is different from the cryptographic Hash of file
When, it is believed that metadata validation failure, the metadata are tampered or forge, and refuse the meta-data preservation.
The present embodiment server 1 receives the metadata for the file that user terminal 2 uploads, and the metadata includes with the file
Multiple data blocks construction Merkel tree in traceable node Hash list;Server 1 is breathed out according to the traceable node
Uncommon list calculates the root cryptographic Hash of the Merkel tree;Server 1 judge described cryptographic Hash whether the Hash with the file
It is worth identical, if identical, determines that the metadata validation passes through, and save the metadata.Compared to the prior art, this implementation
Example improves the safety of block chain data write-in, prevents rogue attacks person using the metadata of loophole data falsification file and usurps
Change file owner, so that the leakage of non-public file is caused, alternatively, invalid data is caused to build consensus in block chain.
Further, in the present embodiment, before the metadata that the server 1 receives that user terminal 2 uploads, this method
Further include:
The file is cut into the data block (example of the first preset quantity by user terminal 2 according to predetermined segmentation rules
Such as, 8 data blocks B1, B2, B3, B4, B5, B6, B7, B8 shown in fig. 5.), and calculated using predetermined hash algorithm
Corresponding first cryptographic Hash of each data block, it is silent according to first cryptographic Hash and the construction rule building of predetermined Merkel tree
Ke Er tree.
The predetermined segmentation rules include:
The data file is cut into the data block of identical first preset quantity of size of data;Alternatively,
First preset quantity is denoted as M, when M is the natural number more than or equal to 2, according to predetermined file
The mapping relations of magnitude range and cutting data block size determine the data block size that data file described in cutting obtains, according to
The character sequence of determining the data block size and the data file, data file described in cutting obtain the identical M- of size
1 data block, remaining after cutting is m-th data block.M data block size is different from M-1 data block size.
For example, the predetermined hash algorithm has MD5, SHA1 etc..The predetermined Merkel tree construction rule
Then include:
Using each first cryptographic Hash as the most junior Hash value node of Merkel tree;
Each first cryptographic Hash is grouped according to predetermined rule of classification to obtain several the first groupings, for
All first cryptographic Hash in each first grouping, calculate corresponding second Hash using predetermined hash algorithm
Value;
For the N cryptographic Hash being calculated, N is the natural number more than or equal to 2, and circulation executes following steps: described
The quantity of N cryptographic Hash only one when terminate cryptographic Hash calculating, using N cryptographic Hash as the most higher level cryptographic Hash of Merkel tree
Node;Alternatively, when the quantity of the N cryptographic Hash has multiple, using each N cryptographic Hash as the inverse of the Merkel tree
N grades of Hash value nodes are grouped all N cryptographic Hash according to predetermined rule of classification to obtain several N points
Group calculates a corresponding N+1 using predetermined hash algorithm and breathes out for the N cryptographic Hash in each N grouping
Uncommon value.
Predetermined rule of classification includes the first rule of classification and V rule of classification, and wherein V is more than or equal to 2
Natural number.
First rule of classification includes:
The data block of cutting is ranked up according to the character sequence of the data file to be slit, according to described each
Corresponding first cryptographic Hash of each data block is ranked up to obtain by the putting in order of data block to be made of all first cryptographic Hash
First set selects the first cryptographic Hash of the second preset quantity as one every time according to collating sequence from the first set
One grouping then will be described until the quantity of the first cryptographic Hash remaining in the first set is less than second preset quantity
Remaining first cryptographic Hash is grouped as one first in first set, terminates the first grouping process.
For example, the collating sequence of 8 data blocks shown in fig. 5 is B1, B2, B3, B4, B5, B6, B7, B8, then this 8 numbers
Collating sequence according to corresponding first cryptographic Hash of block is H1 (B1), H2 (B2), H3 (B3), H4 (B4), H5 (B5), H6 (B6), H7
(B7),H8(B8).H1 (B1), H2 (B2) in Fig. 5 are one first grouping.Second preset quantity and the first preset quantity can
With identical, can also be different, the second preset quantity can be 2.
V rule of classification, V are more than or equal to 2 natural number: according to putting in order to V for each -1 cryptographic Hash of V
Cryptographic Hash is ranked up to obtain the V set being made of all V cryptographic Hash, each from the V set according to collating sequence
The V cryptographic Hash of the second preset quantity is selected to be grouped as a V, until V cryptographic Hash remaining in the V set
Quantity is less than second preset quantity, then V cryptographic Hash work remaining in the V set is divided into a V grouping,
Terminate V and is grouped process.For example, the second cryptographic Hash H12 (H1+H2), the second cryptographic Hash H34 (H3+H4) in Fig. 5 are one
Second packet.
The above description is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all at this
Under the inventive concept of invention, using equivalent structure transformation made by description of the invention and accompanying drawing content, or directly/use indirectly
It is included in other related technical areas in scope of patent protection of the invention.