区块链特性里面的唯一性,主要就是通过哈希算法来进行的。
在区块链中,每个新区块都包含上一个区块经过科学方法算出来的数据指纹——哈希值。这个值让一个个区块之间形成了有着严格顺序关系的链条结构,一旦某个区块中的任何数据被篡改,该区块在下一个区块头部的数据指纹——哈希值就会变动,之后就无法衔接上来,也就不会被任何人认可。
那新的区块出现,要保证上一个区块的数据能记录和链接,这时候就会把上一个区块变成哈希值,这个哈希值里面,包含了上一个区块的所有交易记录。也就是说,上一个区块的数据,是被压缩成哈希值放在新的区块里面,这样一来,当有人想去修改上一个区块的数据,那就需要将新的区块数据也修改,因为新的区块里面,已经有了上一个区块的数据。
区块越多,篡改的难度就越大;生成的区块是大家达成的共识,所以这个时候要是有去修改,就不会得到确认。
所以在区块链中,每个区块都包含上一个区块所有数据包的数据指纹(哈希值),计算当前区块的数据指纹(哈希值)时,同时包含了上一个区块的数据指纹(哈希值),形成链接关系。
所以,一旦任何某个区块数据产生变动,后续所有区块的数据指纹(哈希值)都会变动,所有人都能发现数据被篡改,并丢弃且不认可这种无效数据。这就保证了区块链数据的不可篡改。
Error correction
Using a hash function can intuitively detect errors that occur during data transmission.At the sender of the data,apply a hash function to the data to be sent and send the calculated result together with the original data.At the receiver of the data,the same hash function is applied to the received data again.If the results calculated by the two hash functions are inconsistent,it indicates that there is an error in some parts of the data transmission process.This is called redundancy check.
speech recognition
For applications such as matching an MP3 file from a known list,one possible solution is to use traditional hash functions such as MD5,but this approach is very sensitive to time translation,CD read errors,different audio compression algorithms,or implementation mechanisms for volume adjustment.Using methods similar to MD5 is beneficial for quickly finding audio files that are strictly identical(based on the binary data of the audio files),but finding all identical(based on the content of the audio files)requires the use of other more advanced algorithms.
information safety
The application of Hash algorithm in information security is mainly reflected in the following three aspects:
File verification:We are familiar with parity and CRC verification algorithms,which do not have the ability to resist data tampering.They can detect and correct channel errors in data transmission to some extent,but cannot prevent malicious damage to data.The"digital fingerprint"feature of the MD5 Hash algorithm makes it the most widely used file integrity checksum algorithm.
Digital signature:Hash algorithm is also an important component of modern cryptography.Due to the slow computational speed of asymmetric algorithms,one-way hash functions play an important role in digital signature protocols.Digitally signing Hash values,also known as"digital digests,"can be considered equivalent to digitally signing the file itself in statistics.And this protocol has other advantages.
Authentication protocol:Authentication protocol,also known as challenge authentication mode,is a simple and secure method in situations where the transmission channel can be intercepted but cannot be tampered with.
public class ConsistentHashingWithoutVirtualNode{
}
Common hash function
MD5 and SHA1 can be said to be the most widely used hash algorithms currently,and they are both designed based on MD4.
MD4(RFC 1320)was designed by Ronald L.Rivest of MIT in 1990,and MD is the abbreviation for Message Digest.It is suitable for implementation with high-speed software on 32-bit word length processors-it is based on bit operations of 32-bit operands.
MD5(RFC 1321)is an improved version of MD4 by Rivest in 1991.It still groups the input in 512 bits,and its output is a cascade of 4 32-bit words,the same as MD4.MD5 is more complex and slower than MD4,but it is safer and performs better in terms of resistance to analysis and differentiation.
SHA1 is designed by NIST NSA to be used together with DSA.It generates a hash value of 160bit for inputs with a length less than 264,resulting in better brute force resistance.SHA-1 was designed based on the same principles as MD4 and imitated the algorithm.