16 stable releases

1.5.0 Jan 3, 2024
1.4.0 Aug 22, 2023
1.2.2 Jul 20, 2023
1.1.2 Feb 10, 2023
0.1.0 Mar 20, 2018

#32 in Cryptography

Download history 62565/week @ 2024-09-10 52339/week @ 2024-09-17 59811/week @ 2024-09-24 59413/week @ 2024-10-01 57610/week @ 2024-10-08 66335/week @ 2024-10-15 68177/week @ 2024-10-22 68920/week @ 2024-10-29 184494/week @ 2024-11-05 208343/week @ 2024-11-12 203465/week @ 2024-11-19 128056/week @ 2024-11-26 163195/week @ 2024-12-03 229304/week @ 2024-12-10 165184/week @ 2024-12-17 39197/week @ 2024-12-24

621,537 downloads per month
Used in 304 crates (195 directly)

MIT/Apache

18KB
341 lines

sha256 crypto digest

GitHub Actions Crates.io Docs.rs Download

Examples

sha256 digest function

use sha256::digest;

fn main() {
    let input = String::from("hello");
    let val = digest(input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest &str
    let input = "hello";
    let val = digest(input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest &mut &str
    let mut input = "hello";
    let val = digest(&mut input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest char
    let mut input = "π";
    let val = digest(input);
    assert_eq!(val,"2617fcb92baa83a96341de050f07a3186657090881eae6b833f66a035600f35a");


    let input = b"hello";
    let val = digest(input);
    assert_eq!(val, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
}

sha256 try_digest function

use sha256::try_digest;
use std::path::Path;

fn main() {
    let input = Path::new("./foo.file");
    let val = try_digest(input).unwrap();
    assert_eq!(val,"433855b7d2b96c23a6f60e70c655eb4305e8806b682a9596a200642f947259b1");
}

Dependencies

~0.7–7.5MB
~56K SLoC