| Crates.io | office-crypto |
| lib.rs | office-crypto |
| version | 0.2.0 |
| created_at | 2023-01-18 03:31:39.641321+00 |
| updated_at | 2025-11-29 01:34:17.952529+00 |
| description | Pure Rust library to decrypt password-protected MS Office files |
| homepage | https://github.com/udbhav1/office-crypto |
| repository | https://github.com/udbhav1/office-crypto |
| max_upload_size | |
| id | 761494 |
| size | 73,865 |
Pure Rust library to decrypt password-protected MS Office files.
This crate exposes two functions: decrypt_from_file and decrypt_from_bytes, which do exactly what they say they do. The resulting bytes can then be interpreted by any MS Office parser like docx-rs or calamine.
use docx_rs::read_docx;
use office_crypto::decrypt_from_file;
let path = "protected.docx";
let decrypted = decrypt_from_file(path, "Password1234_").unwrap();
let docx = read_docx(&decrypted).unwrap();
Non-SHA512 hash functions are not yet implemented. This only affects Agile encrypted files, but I have yet to find one that doesn't use SHA512.
Measured on an M4 Max:
test bench_agile_sha512 ... bench: 15,029,308 ns/iter (+/- 372,423)
test bench_agile_sha512_large ... bench: 45,220,041 ns/iter (+/- 3,078,352)
test bench_standard ... bench: 3,080,678 ns/iter (+/- 95,020)
test bench_doc97_rc4_cryptoapi ... bench: 42,690 ns/iter (+/- 1,393)
File sizes for tests:
bench_agile_sha512 => 25 KBbench_agile_sha512_large => 7.1 MBbench_standard => 7 KBbench_doc97_rc4_cryptoapi => 23 KBNote that the latest version of Word will create an Agile encrypted document.
This crate is essentially a port of the OOXML-specific features from msoffcrypto and olefile.