Socket
Socket
Sign inDemoInstall

officecrypto-tool

Package Overview
Dependencies
6
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

tests/excel/excel.test.js

6

index.d.ts

@@ -41,2 +41,8 @@

function decrypt(input: Buffer, options: Options): Promise<Buffer>;
/**
* @param input Input buffer
* @description Determine whether excel file is encrypted or not, support xls and xlsx format, encrypted is true, not encrypted is false.
*/
function isEncrypted(input: Buffer): boolean;
}

@@ -107,4 +107,36 @@ /* eslint-disable valid-jsdoc */

/**
*
* @param {*} input
* @returns
*/
function isEncrypted(input) {
if (!Buffer.isBuffer(input)) {
// This is an ArrayBuffer in the browser. Convert to a Buffer.
if (ArrayBuffer.isView(input)) {
input = Buffer.from(input);
} else {
throw new Error('The input must be a buffer');
}
}
const cfb = CFB.read(input, {type: 'buffer'});
const encryptionInfo = CFB.find(cfb, '/EncryptionInfo');
if (encryptionInfo) return true;
const Workbook = CFB.find(cfb, 'Workbook');
if (Workbook) {
let blob = Workbook.content;
if (!Buffer.isBuffer(blob)) blob = Buffer.from(blob);
const bof = blob.read_shift(2);
const bofSize = blob.read_shift(2);
blob.l = blob.l + bofSize; // -> skip BOF record
const filePass = blob.read_shift(2);
if (filePass === 47) { // 'FilePass': 47,
return true;
}
}
return false;
}
exports.decrypt = decrypt;
exports.encrypt = encrypt;
exports.isEncrypted = isEncrypted;

5

package.json
{
"name": "officecrypto-tool",
"version": "0.0.4",
"version": "0.0.5",
"description": "officeCrypto is a library for node.js that can be used to decrypt and encrypt excel files.",

@@ -24,3 +24,4 @@ "keywords": [

"test": "jest",
"coverage": "jest --coverage"
"coverage": "jest --coverage",
"testExcel": "jest tests/excel/excel.test.js"
},

@@ -27,0 +28,0 @@ "types": "index.d.ts",

13

README.md

@@ -9,3 +9,3 @@ # officecrypto-tool

Now it supports encryption and decryption of` MS office and WPS xlsx suffix files`, `xls suffix` encryption and decryption is not supported yet.
Now it supports encryption and decryption of` MS office and WPS xlsx suffix files`, `xls suffix` encryption is not supported yet.

@@ -53,2 +53,13 @@ ## Contents

})()
//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
})()
```

@@ -55,0 +66,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc