Cannot determine whether the file is password protected
Closed this issue · 11 comments
I have created a Password protected .xls (Not .xlsx) file using MS Excel on Macbook and trying to determine using officecrypto-tool whether the file is password protected. It is not able to determine correctly. I have used the following code:
const arrayBuffer = this.result;
const uint8Array = new Uint8Array(arrayBuffer);
try {
// Check if the file is encrypted
const encrypted = isEncrypted(uint8Array);
file.isProtectedFile = encrypted;
} catch (error) {
console.error('Error reading the file:', error);
file.isProtectedFile = false;
}
This is the file which I tried
sample3.xls
@manik-ushur Can you provide your version of MS Excel?
@manik-ushur Can you provide your version of MS Excel?
Thanks @zurmokeeper for your response. Here you go: Version 16.87 (24071426)
Thanks, I've found the problem.
Can you provide me with the password for sample.xls? Or can you create a new encrypted xls file with random contents for me? I don't have such a file.
I'd like to test if you can decrypt this file properly, as this also affects the decryption method.
Password$456
@manik-ushur v0.0.14 has been released, just upgrade and install the latest version!
@zurmokeeper Thanks for the quick fix. 'isEncrypted' method works now, but there's an issue with the 'decrypt' method as well. It resolves as true even with the wrong password, and not entering the catch block.
Below is the code:
const uint8Array = new Uint8Array(arrayBuffer);
try {
await officeCrypto.decrypt(uint8Array, { password: password });
resolve(true);
} catch (error) {
if (error.message.includes('Password')) {
resolve(false); // Password is incorrect
}
}
@krishna-ushur Yes, there is indeed a problem here, and I've found it, but it's going to take some time to fix, so I went ahead and posted a new version dealing with the isEncrypted method.
thanks @zurmokeeper We would want the decrypt feature as well. Shall we create another ticket?
@manik-ushur Yes, you can.
@manik-ushur @krishna-ushur v0.0.15 has been released to support BIFF5 decryption, just upgrade and install the latest version! Try this version.
Thanks a lot @zurmokeeper. We will give it a try and update you.