Recent

Author Topic: Read ods with password?  (Read 2552 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Read ods with password?
« on: January 17, 2022, 04:43:32 pm »
Hi,
with this code, i can read a file ods without password:
Code: Pascal  [Select][+][-]
  1.   MyWorkbook:=TsWorkbook.Create;
  2.   try
  3.     MyWorkbook.ReadFromFile('PwdNo.ods', sfOpenDocument);
  4.  
  5.     MyWorksheet:=MyWorkbook.GetFirstWorksheet;
  6.     Memo1.Lines.Add('File without password: Col = ' +
  7.                     IntToStr(MyWorksheet.GetLastColIndex(False)) +
  8.                     ' - Row = ' +
  9.                     IntToStr(MyWorksheet.GetLastRowIndex(False)));
  10.   finally
  11.     FreeAndNil(MyWorkbook);
  12.   end;
  13.  

Now, the same file have been protected with password.
I've tried with the code avove, but it fails:
Code: Pascal  [Select][+][-]
  1.   MyWorkbook:=TsWorkbook.Create;
  2.   try
  3.     MyWorkbook.ReadFromFile('PwdYes_123456.ods', '123456'{, sfOpenDocument});
  4.  
  5.     MyWorksheet:=MyWorkbook.GetFirstWorksheet;
  6.     Memo1.Lines.Add('File with password: Col = ' +
  7.                     IntToStr(MyWorksheet.GetLastColIndex(False)) +
  8.                     ' - Row = ' +
  9.                     IntToStr(MyWorksheet.GetLastRowIndex(False)));
  10.   finally
  11.     FreeAndNil(MyWorkbook);
  12.   end;
  13.  

Someone can help me?

Thanks, Mario

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Read ods with password?
« Reply #1 on: January 17, 2022, 05:47:45 pm »
fpspreadsheet does not support encrypted files.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Read ods with password?
« Reply #2 on: January 17, 2022, 06:05:59 pm »
You would need to unzip the content of the ods yourself (not protected) and look in the META-INF/manifest.xml. It will show how the files are encrypted (probably aes256-cbc). The initialisation-vector (IV) is also in there. With that you could try to decrypt all the files mentioned in that manifest.xml  (a recent post here shows some code to decrypt AES-256-CBC with TDCP_rijndael). After that you can rezip the contents back to an unprotected ods-file and read it with fpspreadsheet. (Don't forget to remove the encryption-data parts in the manifest.xml)

Maybe you also need to do something (PBKDF2) with the password. See https://askubuntu.com/a/223183/926892 for more details.
« Last Edit: January 17, 2022, 06:13:25 pm by rvk »

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Read ods with password?
« Reply #3 on: January 18, 2022, 08:36:51 am »
Ok, thanks

 

TinyPortal © 2005-2018