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 of MS office and WPS xlsx suffix files
, xls suffix
encryption is not supported yet.
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
Other
PRs are welcome!
Tests
With Jest:
pnpm i
pnpm run test
Todo
Resources
In other languages