如何使用POI验证doc文件?

时间:2018-04-20 07:55:20

标签: java apache-poi digital-signature verification

我正在使用Apache POI来验证office word文件。如果我的文件格式是docx,则验证工作。但如果是doc,我得到的答案无效。

  

org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException:提供的数据似乎是OLE2格式。您正在调用处理OOXML(Office Open XML)文档的POI部分。您需要调用POI的不同部分来处理此数据(例如HSSF而不是XSSF)       在org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:179)       在org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipFile(ZipHelper.java:237)       在org.apache.poi.openxml4j.opc.ZipPackage。(ZipPackage.java:134)       在org.apache.poi.openxml4j.opc.ZipPackage。(ZipPackage.java:117)       在org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:257)       在org.apache.poi.openxml4j.opc.OPCPackage $ open.call(未知来源)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)       在com.edao.ss.docsig.ms.POIOfficeSigner.verify(POIOfficeSigner.groovy:170)       at com.edao.ss.docsig.ms.POIOfficeSigner $ verify.call(Unknown Source)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)       at signOfficeTest.verify(signOfficeTest.groovy:27)       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)       在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)       在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)       在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)       在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)       在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)       在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)       在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)       在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)       在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)       在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)       在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)       在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)       在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)       在org.junit.runners.ParentRunner.run(ParentRunner.java:363)       在org.junit.runner.JUnitCore.run(JUnitCore.java:137)       在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)       在com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)       在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)       在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

以下是官方代码:

 OPCPackage opcPackage = OPCPackage.open(file , PackageAccess.READ)
            SignatureConfig signatureConfig = new SignatureConfig()
            signatureConfig.setOpcPackage(opcPackage)
            SignatureInfo signatureInfo = new SignatureInfo()
            signatureInfo.setSignatureConfig(signatureConfig)
            result = signatureInfo.verifySignature()

0 个答案:

没有答案