首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sha3::Keccak256结构中没有新的()

sha3::Keccak256结构中没有新的()
EN

Stack Overflow用户
提问于 2022-01-06 13:36:18
回答 1查看 434关注 0票数 1

我正试着从一把魔法私钥上得到一个以太的公共地址。我写了一个生锈的剧本-

代码语言:javascript
复制
extern crate hex;
extern crate secp256k1;
extern crate sha3;

use secp256k1::{PublicKey, SecretKey};
use sha3::Keccak256;

fn main() {
    let context = secp256k1::Secp256k1::new();
    let private_key: &[u8] =
        "616E6769652E6A6A706572657A616775696E6167612E6574682E6C696E6B0D0A".as_bytes();
    let secret_key = SecretKey::from_slice(&hex::decode(private_key).unwrap());
    let public_key = PublicKey::from_secret_key(&context, &secret_key.unwrap());
    println!("Public Key -> {:?}", public_key);
    let mut hasher = Keccak256::new();
    // making it an ethereum address
}

let mut hasher = Keccak256::new();给了我一个错误-

代码语言:javascript
复制
error[E0599]: no function or associated item named `new` found for struct `CoreWrapper` in the current scope
  --> src/main.rs:14:33
   |
14 |     let mut hasher = Keccak256::new();
   |                                 ^^^ function or associated item not found in `CoreWrapper<Keccak256Core>`
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
5  | use crate::sha3::Digest;
   |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `ecdsa-test` due to previous error
EN

回答 1

Stack Overflow用户

发布于 2022-09-22 18:47:36

试试这个:

代码语言:javascript
复制
use sha3::{Digest, Sha3_256};

let mut hasher = Sha3_256::new();
hasher.update(message);
let result = hasher.finalize();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70607940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档