Getting NoSuchAlgorithmException when converting XLSX to pdf

I am using groupdocs viewer for Java 21.2 and converting a password protected xlsx file to PDF. But getting below exception. Below are my system specifications.

JDK 1.8.0_302
Ubuntu 16.04
16 GB RAM

java.security.NoSuchAlgorithmException: no such algorithm: SHA-512 for provider BC
at sun.security.jca.GetInstance.getService(GetInstance.java:101)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:218)
at java.security.Security.getImpl(Security.java:724)
at java.security.MessageDigest.getInstance(MessageDigest.java:278)
at com.securelyshare.groupdocs.test.ConvertDocTest.type(ConvertDocTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:108)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

Code snippet

    @Test
void convertPf() throws FileNotFoundException, NoSuchAlgorithmException {
    PdfViewOptions pdfViewOptions;
    LoadOptions l = new LoadOptions(FileType.XLSX);
    l.setPassword("test@123");
    pdfViewOptions = createPdfViewOptions(new FileOutputStream("converted.pf"));
    try (Viewer viewer = new Viewer(
        getClass().getResourceAsStream("//to test.xlsx"),
        l)) {
        FileInfo vi = viewer.getFileInfo();
        System.out.println(vi);
        viewer.view(pdfViewOptions);
    }
}

private PdfViewOptions createPdfViewOptions(OutputStream destination) {
    PdfViewOptions p = new PdfViewOptions(new FileStreamFactory() {
        @Override
        public OutputStream createFileStream() {
            return destination;
        }

        @Override
        public void closeFileStream(OutputStream arg0) {
            // stream will be closed by servlet container.
        }
    });
    // setWatermarkOptions(p);
    SpreadsheetOptions s = SpreadsheetOptions.forSplitSheetIntoPages(100);
    s.setRenderGridLines(true);
    s.setRenderHeadings(true);
    p.setSpreadsheetOptions(s);
    return p;
}

@shiva.k

Can you please attach your file?

to test.docx (15 KB)
Plz rename .docx to .xlsx since the forum chat did not allowed me to upload xlsx file. Password is test@123

@shiva.k

Thank you for attaching the sample file. We have reproduced this issue at our end and logged it in our internal bug-tracker with ID VIEWERJAVA-2721. We’ll update you here when we have any new information.

@shiva.k

Here are some details about the issue. This issue is related to the bouncycastle dependency that contains different security providers. This library is signed by Oracle but when we’re embedding this library into GroupDocs.Viewer the signature is becoming invalid that leads to the exception you’re experiencing.

To avoid this issue starting from the next version we’ll make bouncycastle an external dependency. We do have plans to release the new version next week.

Unfortunately, we can’t provide a workaround for 21.2 as adding a reference to bouncycastle can’t fix the issue.

Can you please let me know the version in which bouncycastle made and external dependency.
Note: Purchased GroupDocs Total for Java OEM License

@channappa

This issue has been fixed in GroupDocs.Viewer for Java 21.11.

In case you get java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider exception please follow Troubleshooting ClassNotFoundException BouncyCastleProvider exception documentation article and reference BouncyCastleProvider:

<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk16</artifactId>
    <version>1.46</version>
</dependency>

Please let us know if it works for you.

@vladimir.litvinchik This is working for me thanks. But the same issue present in watermark sdk. Please consider that as well.

@shiva.k

Thank you for your response. Please create a new issue in GroupDocs.Watermark category and reference this issue.