哈希算法就是把任意长度的输入变换成固定长度的输出,每个字节都会对输出值产生影响,且无法通过输出逆向计算得到输入。
哈希算法主要包含构造函数及冲突解决两部分内容。I8O量化2857交易8624系统开发
The constructor criterion of hash algorithm is relatively simple and uniform,that is,the constructor can quickly calculate the hash value,and the constructor can evenly distribute the keyword set on the output address set{0,1,...,n-1}to ensure the minimum possibility of conflict.
当前已经提出并被广泛使用的算法包括消息摘要算法(Message-DigestAlgorithm,MD)系列和安全散列算法(Secure Hash Algorithm,SHA)家族。
MD系列主要由MIT的Ronald L.Rivest设计,1989年开发出第一个版本MD2算法,对输入值的字节数补齐成16的倍数,然后再加上一个16位校验值,最后基于该值输出哈希值。但是该方法如果忽略了校验将会产生冲突。
为了加强算法的安全性,在1990年推出MD4版本。
但是人们很快就发现了MD4的漏洞,利用当时的一台个人电脑几分钟就可找到MD4中的冲突,即发生碰撞。
1991年在MD4的基础上,又增加“安全—带子”(Safety-belts)的概念,推出MD5版本。
MD5相比MD4更复杂、更安全,也因此计算速度稍慢。
MD5在很长一段时间内被广泛使用,当前主流的编程语言均实现了MD5算法。
但是,现在MD5也被证明不具备“强抗碰撞性”。
只要通过穷举的方法,很快就可以找到一组碰撞的输入。
由于计算性能的飞跃提升,当前的智能手机几秒钟就可以找到一个hash碰撞的例子,所以MD5已经不推荐作为散列方案。
springboot使用web3进行代币交换(uniswap):
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.StaticArray;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.RawTransaction;
import org.web3j.crypto.TransactionEncoder;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthGasPrice;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;
import org.web3j.utils.Numeric;
import io.renren.common.utils.R;
import net.sf.json.JSONObject;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70016646/viewspace-2936737/ ,如需转载,请注明出处,否则将追究法律责任。