officecrypto-tool
officecrypto-tool is a library for js that can be used to decrypt and encrypt office(excel/ppt/word) files..
Special Notes
The implementation of this library refers to xlsx and xlsx-populate, especially xlsx-populate
, part of the source code reference and directly copied over.
Now it supports encryption and decryption ofMS office and WPS files
, Support doc docx xls xlsx ppt pptx
decryption, support xls decryption in BIFF8 and BIFF5 formats. support docx xlsx pptx
encryption.
Contents
Install
npm/yarn/pnpm install officecrypto-tool
Examples
const officeCrypto = require('officecrypto-tool');
const fs = require('fs').promises;
//decrypt a file with a password
(async ()=>{
const input = await fs.readFile(`pass_test.xlsx`);
const output = await officeCrypto.decrypt(input, {password: '123456'});
await fs.writeFile(`out_success.xlsx`, output);
})()
//Setting up encrypted files with passwords
(async ()=>{
const input = await fs.readFile(`test.xlsx`);
const output = officeCrypto.encrypt(input, {password: '123456'});
await fs.writeFile(`standard_out_success.xlsx`, output);
})()
//Determine whether excel file is encrypted or not, support xls and xlsx format, encrypted is true, not encrypted is false.
(async ()=>{
const input = await fs.readFile(`encrypted_test.xlsx`);
const isEncrypted = officeCrypto.isEncrypted(input);
// output: true
const input1 = await fs.readFile(`not_encrypted_test.xlsx`);
const isEncrypted1 = officeCrypto.isEncrypted(input1);
// output: false
})()
Supported encryption methods
OFFICECRYPTO specs
- <input checked="" disabled="" type="checkbox"> ECMA-376 (Agile Encryption/Standard Encryption)
- <input checked="" disabled="" type="checkbox"> MS-DOCX (OOXML) (Word 2007-2016)
- <input checked="" disabled="" type="checkbox"> MS-XLSX (OOXML) (Excel 2007-2016)
- <input checked="" disabled="" type="checkbox"> MS-PPTX (OOXML) (PowerPoint 2007-2016)
- <input checked="" disabled="" type="checkbox"> Office Binary Document RC4 CryptoAPI
- <input checked="" disabled="" type="checkbox"> MS-DOC (Word 2002, 2003, 2004)
- <input checked="" disabled="" type="checkbox"> MS-XLS (Excel 2002, 2003, 2004) (experimental)
- <input checked="" disabled="" type="checkbox"> MS-PPT (PowerPoint 2002, 2003, 2004) (partial, experimental)
- <input checked="" disabled="" type="checkbox"> Office Binary Document RC4
- <input checked="" disabled="" type="checkbox"> MS-DOC (Word 97, 98, 2000)
- <input checked="" disabled="" type="checkbox"> MS-XLS (Excel 97, 98, 2000) (experimental)
- <input checked="" disabled="" type="checkbox"> XOR Obfuscation
- <input checked="" disabled="" type="checkbox"> MS-XLS
- [] MS-DOC
- <input disabled="" type="checkbox"> ECMA-376 (Extensible Encryption)
Other
- <input disabled="" type="checkbox"> Word 95 Encryption And Decryption (Word 95 and prior)
- <input disabled="" type="checkbox"> Excel 95 Encryption And Decryption (Excel 95 and prior)
- <input disabled="" type="checkbox"> PowerPoint 95 Encryption And Decryption (PowerPoint 95 and prior)
PRs are welcome!
Tests
Now that the files referenced by the test use case have been modified to submodule
dependencies, if you have not downloaded the submodule
dependencies, execute the following command:
-> tests/
1: git submodule init
2: git submodule update
Then check to see if the test_files
directory is already in the tests
directory and if all the files in it are there.
With Jest:
pnpm i
pnpm run test
Todo
- <input checked="" disabled="" type="checkbox"> Add tests
- <input checked="" disabled="" type="checkbox"> Support decryption and encryption with passwords
- <input checked="" disabled="" type="checkbox"> Support older encryption schemes
- <input checked="" disabled="" type="checkbox"> Add decryption tests for various file formats
- <input checked="" disabled="" type="checkbox"> Support frontend
- <input disabled="" type="checkbox"> Support more encryption and decrytion
Resources
- Technical Documents https://learn.microsoft.com/en-us/openspecs/office_file_formats/MS-OFFFFLP/6ae2fd93-51fc-4e75-a54a-1b175c627b51