Hello,
using Java 21/POI, we’re creating encrypted XLSX files. The encryption settings were taken from POI’s tutorial at Apache POI™ - Encryption support - section " XML-based formats - Encryption":
try (POIFSFileSystem fs = new POIFSFileSystem()) {
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("foobaa"); // of course, we're using a different password, in this case, it has 6 characters
// Read in an existing OOXML file and write to encrypted output stream
// don't forget to close the output stream otherwise the padding bytes aren't added
try (OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs)) {
opc.save(os);
}
// Write out the encrypted version
try (FileOutputStream fos = new FileOutputStream("...")) {
fs.writeFilesystem(fos);
}
}
The file is then send to me via email (usually, it’s for external users, but I’m currently developing something here).
Now, this file can opened using Excel 365 on multiple machines w/o any issues.
But LibreOffice doesn’t even dare to ask for password, it handles it as if it was a CSV file - asking for details on how to open it:
Any ideas, why it is failing? Before those changes, we could open encrypted XLS files.
Version: 24.2.7.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 12; OS: Linux 6.8; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: en-US
Ubuntu package version: 4:24.2.7-0ubuntu0.24.04.3
Calc: threaded
Thanks a lot.
kniffte
Update: here’s a sample file created using above code:
audit_28.xlsx (8.5 KB)