Crates.io | md5-rs |
lib.rs | md5-rs |
version | 0.1.5 |
source | src |
created_at | 2022-03-24 04:24:50.309396 |
updated_at | 2022-08-11 14:42:35.61464 |
description | A streamable MD5 implementation, using no_std |
homepage | https://github.com/magnetardev/md5-rs |
repository | https://github.com/magnetardev/md5-rs |
max_upload_size | |
id | 555591 |
size | 11,066 |
A simple MD5 implementation with a focus on buffered reading, and is completely no_std
.
This shouldn't be used in any security-critical software, as MD5 is vulnerable.
I was working on a web project and realized I have no way of getting a checksum of a big file without reading it all into memory (which in some cases crashes the page!). The Web Crypto API doesn't have a MD5 implementation, so I figured rather than re-implementing a SHA algorithm, I'd implement MD5.
As such, the API may be slightly odd since it is mainly focused on WebAssembly.
This isn't as straight forward as other MD5 libraries may be, given that it is no_std
through and through.
use md5_rs::Context;
// get the hash
let mut ctx = Context::new();
ctx.read(b"Hello, world");
let digest = ctx.finish();
// get digest as string
let hash = digest.iter().map(|x| format!("{:02x}", x)).collect::<String>();
println!("{hash}"); // "bc6e6f16b8a077ef5fbc8d59d0b931b9"