https://github.com/baoyachi/sha256-rs
sha256 crypto digest write by rust
https://github.com/baoyachi/sha256-rs
cypto rust sha-256 sha256
Last synced: 14 days ago
JSON representation
sha256 crypto digest write by rust
- Host: GitHub
- URL: https://github.com/baoyachi/sha256-rs
- Owner: baoyachi
- License: apache-2.0
- Created: 2021-01-31T04:41:59.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-03-02T15:18:38.000Z (about 2 months ago)
- Last Synced: 2025-03-28T03:00:55.431Z (about 1 month ago)
- Topics: cypto, rust, sha-256, sha256
- Language: Rust
- Homepage:
- Size: 46.9 KB
- Stars: 38
- Watchers: 2
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# sha256 crypto digest
[docsrs]: https://docs.rs/sha256
[](https://github.com/baoyachi/sha256-rs/actions?query=workflow%3Abuild)
[](https://crates.io/crates/sha256)
[](https://docs.rs/sha256)
[](https://crates.io/crates/sha256)## Examples
#### sha256 digest function
```rust
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
```rust
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");
}
```