Recent

Author Topic: [fpspreadsheet] Read from ods with password  (Read 3210 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
[fpspreadsheet] Read from ods with password
« on: July 23, 2023, 07:07:59 am »
Hi,
sorry for my bad english ...

When i must read from a file Ods, i use this code:
Code: Pascal  [Select][+][-]
  1. MyWorkbook.ReadFromFile(NomeDocSaleranoTmp, sfOpenDocument);

If a file is protected from a password, how can i read from this?



Thanks, Mario

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: [fpspreadsheet] Read from ods with password
« Reply #1 on: July 23, 2023, 01:51:13 pm »
Sorry, password-protection is supported, in a very elemental form, only for Excel XLSX.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: [fpspreadsheet] Read from ods with password
« Reply #2 on: July 23, 2023, 06:09:57 pm »
Don't worry, it's no problem.
Thanks anyway for the excellent work done with this Package

Hi Mario

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: [fpspreadsheet] Read from ods with password
« Reply #3 on: July 31, 2023, 12:20:39 pm »
OK - here is a reader for encrypted ods files. Not heavily tested, but it works at least with my test file. Please note that it depends on the Abbrevia (because the FPC zipper cannot extract the encrypted xml subfiles) and DCPCrypt (because FPC does not provide AES decryption) libraries. You can find both libraries in the OPM. No need to install, just download and open the lpk package file so that the IDE knows where they are. Afterwards you can compile the demo program in the attachment.

rvk

  • Hero Member
  • *****
  • Posts: 6588
Re: [fpspreadsheet] Read from ods with password
« Reply #4 on: July 31, 2023, 01:36:35 pm »
Please note that it depends on  (...) and DCPCrypt (because FPC does not provide AES decryption) libraries.
If you don't want the dependency with DCCrypt, I think this could, theoretically, also be done with calls to openssl (aes-256-cbc)  :D

(Not sure if FPC exposes all the necessary calls.)
« Last Edit: July 31, 2023, 01:38:09 pm by rvk »

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: [fpspreadsheet] Read from ods with password
« Reply #5 on: July 31, 2023, 08:00:16 pm »
Found Wolfgang Ehrhardt's crypto library (https://github.com/chadilukito/www.wolfgang-ehrhardt.de/tree/master/src/crypto) which can be integrated into fpspreadsheet-crypto more easily. Here is the same sample project, now without dependence on DCPcrypt.

rvk

  • Hero Member
  • *****
  • Posts: 6588
Re: [fpspreadsheet] Read from ods with password
« Reply #6 on: August 01, 2023, 11:11:06 am »
Found Wolfgang Ehrhardt's crypto library (https://github.com/chadilukito/www.wolfgang-ehrhardt.de/tree/master/src/crypto) which can be integrated into fpspreadsheet-crypto more easily. Here is the same sample project, now without dependence on DCPcrypt.
It wasn't the dependency to DCPcrypt perse, but if it was possible to use openssl (which would be installed by default everywhere in FPC) that would have been much easier.

But using the openssl functions currently present in FPC to decrypt AES-256-CBC isn't as easy as it looks (but should be possible).
(An example in Delphi https://stackoverflow.com/a/9733823/1037511 but the key creation is somewhat different there)

But for now including Wolfgang's library should be sufficient for use case of TS (and others).

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: [fpspreadsheet] Read from ods with password
« Reply #7 on: August 01, 2023, 11:17:46 am »
but if it was possible to use openssl (which would be installed by default everywhere in FPC) that would have been much easier.
But still the openssl dlls would have to be available at runtime. I would like to keep fpspreadsheet clean of such requirements.

rvk

  • Hero Member
  • *****
  • Posts: 6588
Re: [fpspreadsheet] Read from ods with password
« Reply #8 on: August 01, 2023, 11:42:37 am »
But still the openssl dlls would have to be available at runtime. I would like to keep fpspreadsheet clean of such requirements.
Ah, Ok. No problem. In that case a 3dparty folder in fpspreadsheet is preferable above including the dependency to openssl dlls.

(I guess openssl dll's aren't as standard as I thought  ;D )

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: [fpspreadsheet] Read from ods with password
« Reply #9 on: August 06, 2023, 01:04:22 pm »
Reading a password-protected ods workbook is now included in the svn version of fpspreadsheet (package laz_fpspreadsheet_crypto.lpk)

https://wiki.lazarus.freepascal.org/FPSpreadsheet#Workbook_protection - last paragraph and code.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: [fpspreadsheet] Read from ods with password
« Reply #10 on: August 13, 2023, 10:56:30 am »
Reading a password-protected ods workbook is now included in the svn version of fpspreadsheet (package laz_fpspreadsheet_crypto.lpk)

https://wiki.lazarus.freepascal.org/FPSpreadsheet#Workbook_protection - last paragraph and code.

HI,
sorry for the delay, but I didn't realize there were new replies.
I've seen them now, and I've tried the modifications: you've done a splendid job.

Thanks, Mario

 

TinyPortal © 2005-2018