officecrypto-tool
Advanced tools
Comparing version 0.0.5 to 0.0.6
23
index.js
@@ -10,2 +10,3 @@ /* eslint-disable valid-jsdoc */ | ||
const xls97File = require('./src/util/xls97'); | ||
const doc97File = require('./src/util/doc97'); | ||
@@ -69,6 +70,14 @@ | ||
if (Workbook) { | ||
output = xls97File.decrypt(cfb, Workbook.content, password); | ||
output = xls97File.decrypt(cfb, Workbook.content, password, input); | ||
return output; | ||
} | ||
const WordWorkbook = CFB.find(cfb, 'wordDocument'); | ||
if (WordWorkbook) { | ||
output = doc97File.decrypt(cfb, WordWorkbook.content, password, input); | ||
return output; | ||
} | ||
if (!encryptionInfo) return input; // Not encrypted returns directly to the original buffer | ||
throw new Error('Unsupported encryption algorithms'); | ||
@@ -138,2 +147,14 @@ } | ||
} | ||
const WordDocument = CFB.find(cfb, 'wordDocument'); | ||
if (WordDocument) { | ||
let blob = WordDocument.content; | ||
if (!Buffer.isBuffer(blob)) blob = Buffer.from(blob); | ||
const fibBase = doc97File.parseFibBase(blob); | ||
const fEncrypted = fibBase.fEncrypted; | ||
if (fEncrypted === 1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
@@ -140,0 +161,0 @@ } |
{ | ||
"name": "officecrypto-tool", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "officeCrypto is a library for node.js that can be used to decrypt and encrypt excel files.", | ||
@@ -25,3 +25,4 @@ "keywords": [ | ||
"coverage": "jest --coverage", | ||
"testExcel": "jest tests/excel/excel.test.js" | ||
"testExcel": "jest tests/office/excel.test.js", | ||
"testWord": "jest tests/office/word.test.js" | ||
}, | ||
@@ -28,0 +29,0 @@ "types": "index.d.ts", |
@@ -9,3 +9,3 @@ # officecrypto-tool | ||
Now it supports encryption and decryption of` MS office and WPS xlsx suffix files`, `xls suffix` encryption is not supported yet. | ||
Now it supports encryption and decryption of` MS office and WPS files`, Support doc docx xls xlsx pptx decryption, support docx xlsx pptx encryption. | ||
@@ -75,7 +75,7 @@ ## Contents | ||
* [x] Office Binary Document RC4 CryptoAPI | ||
* [] MS-DOC (Word 2002, 2003, 2004) | ||
* [x] MS-DOC (Word 2002, 2003, 2004) | ||
* [x] MS-XLS (Excel 2002, 2003, 2004) (experimental) | ||
* [] MS-PPT (PowerPoint 2002, 2003, 2004) (partial, experimental) | ||
* [x] Office Binary Document RC4 | ||
* [] MS-DOC (Word 97, 98, 2000) | ||
* [x] MS-DOC (Word 97, 98, 2000) | ||
* [x] MS-XLS (Excel 97, 98, 2000) (experimental) | ||
@@ -82,0 +82,0 @@ * [ ] ECMA-376 (Extensible Encryption) |
@@ -452,3 +452,3 @@ /* eslint-disable valid-jsdoc */ | ||
exports.decrypt = function decrypt(currCfb, blob, password) { | ||
exports.decrypt = function decrypt(currCfb, blob, password, input) { | ||
if (!Buffer.isBuffer(blob)) blob = Buffer.from(blob); | ||
@@ -463,2 +463,5 @@ const bof = blob.read_shift(2); | ||
const filePass = blob.read_shift(2); | ||
if (filePass !== 47) { // 'FilePass': 47, | ||
return input; // Not encrypted returns directly to the original buffer | ||
} | ||
const filePassSize = blob.read_shift(2); | ||
@@ -465,0 +468,0 @@ const wEncryptionType = blob.read_shift(2); |
@@ -8,5 +8,6 @@ | ||
const filePath = './tests/data/decrypt'; | ||
const encryptFilePath = './tests/data/encrypt'; | ||
describe('rc4_crypto_api decrypt', () => { | ||
it('decrypt success', async () => { | ||
it('decrypt xls success', async () => { | ||
const input = await fs.readFile(`${filePath}/rc4_cryptoapi_pass_test.xls`); | ||
@@ -17,2 +18,30 @@ const output = await officeCrypto.decrypt(input, {password: '123'}); | ||
}); | ||
it('decrypt doc success', async () => { | ||
const input = await fs.readFile(`${filePath}/rc4_cryptoapi_pass_test.doc`); | ||
const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
await fs.writeFile(`${filePath}/rc4_cryptoapi_out_success.doc`, output); | ||
// expect(200).toEqual(200); | ||
}); | ||
it('decrypt unencrypted doc success', async () => { | ||
const input = await fs.readFile(`${encryptFilePath}/doc_wait_for_encrypt.doc`); | ||
const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
await fs.writeFile(`${encryptFilePath}/decrypt_unencrypted_doc_success.doc`, output); | ||
// expect(200).toEqual(200); | ||
}); | ||
it('decrypt unencrypted xls success', async () => { | ||
const input = await fs.readFile(`${encryptFilePath}/xls_wait_for_encrypt.xls`); | ||
const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
await fs.writeFile(`${encryptFilePath}/decrypt_unencrypted_doc_success.xls`, output); | ||
// expect(200).toEqual(200); | ||
}); | ||
it('decrypt unencrypted xlsx and docx success', async () => { | ||
const input = await fs.readFile(`${encryptFilePath}/agile_input_test.xlsx`); | ||
const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
await fs.writeFile(`${encryptFilePath}/decrypt_unencrypted_xlsx_success.xlsx`, output); | ||
// expect(200).toEqual(200); | ||
}); | ||
}); |
@@ -10,3 +10,3 @@ | ||
describe('rc4 decrypt', () => { | ||
it('decrypt success', async () => { | ||
it('decrypt xls success', async () => { | ||
const input = await fs.readFile(`${filePath}/rc4_pass_test.xls`); | ||
@@ -17,2 +17,10 @@ const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
}); | ||
it('decrypt doc success', async () => { | ||
const input = await fs.readFile(`${filePath}/doc_rc4_pass_test.doc`); | ||
const output = await officeCrypto.decrypt(input, {password: '123456'}); | ||
await fs.writeFile(`${filePath}/doc_rc4_out_success.doc`, output); | ||
// expect(200).toEqual(200); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
518014
48
2385
8