16个稳定版本

1.5.0 2024年1月3日
1.4.0 2023年8月22日
1.2.2 2023年7月20日
1.1.2 2023年2月10日
0.1.0 2018年3月20日

#19 in 加密学

Download history 42334/week @ 2024-04-08 42522/week @ 2024-04-15 41413/week @ 2024-04-22 41849/week @ 2024-04-29 46258/week @ 2024-05-06 49540/week @ 2024-05-13 45641/week @ 2024-05-20 46740/week @ 2024-05-27 51222/week @ 2024-06-03 56210/week @ 2024-06-10 52057/week @ 2024-06-17 58529/week @ 2024-06-24 52389/week @ 2024-07-01 62812/week @ 2024-07-08 51659/week @ 2024-07-15 57256/week @ 2024-07-22

227,044 每月下载量
241 个crate中使用 (157个直接使用)

MIT/Apache

18KB
341

sha256加密摘要

GitHub Actions Crates.io Docs.rs Download

示例

sha256摘要函数

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函数

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");
}

依赖项

~0.8–2.9MB
~58K SLoC