当前位置:网站首页>One-way hash function

One-way hash function

2022-06-10 14:56:00 MyFreeIT

function The rules

It is easy to calculate the output from the input , however , Push back the input through the output , Can only be exhausted by violence . Because Euler's theorem only gives forward derivation formula , No reverse derivation formula is given .

  1. Hash value, That is, the length of the hash value is fixed
  2. Abstract , That is, different messages Hash value Different
  3. One way , Irreversible
  4. Fast calculation

Application scenarios

One-way hash function It is a kind of cryptographic technology to ensure the integrity of information . For example, when storing a user's password , Just store the password Hash value that will do , Verification time , Just compare the two Hash value You can judge whether the entered password is correct .

  1. Encryption and decryption , password
  2. Interface signature , The received content is Hash value, And received Hash value Contrast , It is the process of signature verification .
  3. Integrity check
  4. Cloud disk second transmission ,Upload when , Produce according to document information Hash value, If it is related to a certain... On the server Hash value equal , Indicates that the file already exists , Directly through Hash value Association is enough .

for example :MySQL The community gives the hash value of the installation file , So that the user can verify whether the file has been tampered after downloading .
 Insert picture description here

Realization way

Hash value( Hash value A summary of the news message digest, The fingerprint fingerprint), Equivalent to the identity of the message
One-way hash function(message digest function Message digest function , hash function , Hash function )
source message(pre-image)
 Insert picture description here

		String book = "It's a book";
		System.out.println(book.hashCode());
		System.out.println(Integer.toHexString(book.hashCode()));
		
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(book.getBytes());
		System.out.println(new BigInteger(1, md.digest()).toString(16));
		
		# -1420758063
		#  ab50f3d1
		#  "It's a book"  =  505fe447e3d0257ff64fbd321849928f    16 Bytes  / 32 Characters 
		#  "It's a book1" =  fd88076e4a8161b76efd6d518bc2c1ce    16 Bytes  / 32 Characters 

Other encoding and encryption methods :

MessageDigest.getInstance("SHA-512")  	64 Bytes /128 Characters 	
#d0988c57f40e049be1aa371e1c9b58ae1bfe1028df925e6429689aff746a69e8
d9d447773d656a1df097b3def2fe36e36cf7b54a4679f486d84b0d4e675a3456

MessageDigest.getInstance("SHA-256")    32 Bytes /64 Characters 
#aa6a7c05f39dcde57599f76c92e2295d86726e4d875e426bbe388941942ffa38

MessageDigest.getInstance("SHA-1") 		20 Bytes /40 Characters 

from Java9 Start supporting SHA-3
 Insert picture description here

The hash algorithm

The bitcoin protocol uses SHA-256 and RipeMD160, among SHA-256 Also called hash256 and dhash,RipeMD160 Is in SHA-256 And then calculate on the result RipeMD160, Also called hash160.
 Insert picture description here
 Insert picture description here

reference 1


  1. One way hash encryption https://blog.51cto.com/gozhuyinglong/4058818

原网站

版权声明
本文为[MyFreeIT]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101449229558.html