We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

NoClassDefFoundError for password protected workbooks

Hi,


I tried to get file format information from the byte array of the attached password protected workbook using the below mention code:

// byte[] inputDoc is the byte array of the workbook.
final InputStream fileStream = new ByteArrayInputStream(inputDoc);
FileFormatInfo info = FileFormatUtil.detectFileFormat(fileStream);

I get NoClassDefFoundError with “org/bouncycastle/jce/provider/BouncyCastleProvider” as the cause.

I was earlier using 8.7.1 version of cells where I wasn’t seeing this exception with the exact same lines of code.

My environment details: Oracle Linux 5 (Intel 64-bit)
Java version: 1.7.0_85(default)
Java SE version: 1.7.0_85 (default)
Aspose cells for java version: 17.3.5

Thanks.


Hi,

Thanks for providing us details.

Well, you need to first add reference to the following library (JAR) into your classpath as well:
bcprov-jdk16-146.jar

This jar file is required when you use (read/write) any file that has AES encryption (supported by MS Excel 2010 or greater versions). You can get this library by downloading/extracting any of our newer versions (you may find this Jar file with the component's main JAR in the folder "\JDK 1.6\lib"), e.g Aspose.Cells for Java 17.3.0 (latest).

I have also tested your scenario/ case using the following sample code with your template file and it works fine and as expected:
e.g
Sample code:

File file = new File("f:\\files\\VariousShapes_3_pwdProtected.xlsx");
int length = (int) file.length();
FileInputStream fstro = new FileInputStream(file);
byte[] bytes = new byte[length];
fstro.read(bytes, 0, length);
fstro.close();

ByteArrayInputStream bas = new ByteArrayInputStream(bytes);
FileFormatInfo info = FileFormatUtil.detectFileFormat(bas);
System.out.println("The spreadsheet format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));
System.out.println("The file is encrypted: " + info.isEncrypted());

Output:
The spreadsheet format is: .xlsx
The file is encrypted: true

Let us know if you still have any issue.

Thank you.

Hi,


The issue is that when we used 8.7.1 in our product, then without adding a separate jar file bcprov-jdk16-146.jar like you mentioned, we could identify that the workbook is protected. This behavior has changed in the version 17.3.5. We have different Aspose products for slides and word, and we don’t have any such issue with those, and we would like the behavior to be consistent. Furthermore, the version of the file bcprov-jdk??.jar available is different across the different Aspose products we have.

Thanks.

Hi,


Well, the bcprov-jdk16-146.jar was also there in the Aspose.Cells for Java v8.7.1. I noticed we can detect a file is protected or not without this file but we still might not detect the file format type fine. For example, in v8.7.1 (without setting the “bcprov-jdk16-146.jar” into classpath), you still cannot detect the file format type, so the following line of code will not give you XLSX file format type:
e.g
Sample code:

System.out.println("The spreadsheet format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));

We did enhance this behavior and you got to add this file “bcprov-jdk16-146.jar” into classpath if your template file is encrypted. Furhtermore, I think there won’t be any issue if you use a single “bcprov-xxx-xxx.jar” into classpath for all the Aspose products.

Thank you.
Hi,

Actually, we enhanced the feature FileFormatUtil.detectFileFormat() in the new versions. If the Window or Structure of the workbook is protected, the file is encrypted with the default password.
MS Excel can open these files without password, so both our customers and we do not think these files are encrypted.Then we have to check whether the file is encrypted with the default password or not.

Thank you.