dalek-cryptography / ed25519-dalek

Fast and efficient ed25519 signing and verification in Rust.
BSD 3-Clause "New" or "Revised" License
683 stars 227 forks source link

signing_key.sign_prehashed ... method not found in `SigningKey` #321

Closed diudiudiuu closed 1 month ago

diudiudiuu commented 1 month ago
use ed25519_dalek::SigningKey;
use ed25519_dalek::Signature;
use sha2::{Sha512, Digest};
use hex_literal::hex;

pub fn sign(message: &str) -> String {

    let sec_bytes = hex!("b23dfd4a2ca755e6ddccfcaa31201d1f6ec7fe0290086d53b931e0cd1a6f80fd");
    let signing_key = SigningKey::from_bytes(&sec_bytes);

    let mut prehash_for_signing = Sha512::default();
    prehash_for_signing.update(message.as_bytes());

    let signature: Signature = signing_key.sign_prehashed(prehash_for_signing, None).unwrap();
    hex::encode(signature.to_bytes())
}

ed25519-dalek = "2.1.1" hex = "0.4.3" hex-literal = "0.4.1" sha2 = "0.10.8"

image Who can help me

robjtede commented 1 month ago

Available on crate feature digest only.

- https://docs.rs/ed25519-dalek/2.1.1/ed25519_dalek/struct.SigningKey.html#method.sign_prehashed

Did you enable the digest feature?

tarcieri commented 1 month ago

Dup of https://github.com/dalek-cryptography/curve25519-dalek/issues/700