web3.sha3

优质
小牛编辑
122浏览
2023-12-01

web3.sha3(string, options)

参数:

  1. String - 传入的需要使用Keccak-256 SHA3算法进行哈希运算的字符串。
  2. Object - 可选项设置。如果要解析的是hex格式的十六进制字符串。需要设置encodinghex。因为JS中会默认忽略0x

返回值:

String - 使用Keccak-256 SHA3算法哈希过的结果。

示例:

//省略初始化过程
var hash = web3.sha3("Some string to be hashed");
console.log(hash); 
var hashOfHash = web3.sha3(hash, {encoding: 'hex'});
console.log(hashOfHash);