当尝试运行.jar文件时发生错误,由于充气城堡库未签名或某种原因。
Exception in thread "main" java.lang.SecurityException: JCE cannot authenticate the provider BC
at javax.crypto.Cipher.getInstance(Cipher.java:656)
at com.bmw.cxml.CryptoUtils.aesDecrypt(CryptoUtils.java:54)
at com.bmw.cxml.CryptoUtils.aesDecryptCBC(CryptoUtils.java:19)
at com.bmw.cxml.ServiceDpParser.patchData(ServiceDpParser.java:37)
at com.bmw.SACXMLPatcher.patchFiles(SACXMLPatcher.java:36)
at com.bmw.App.main(App.java:16)
Caused by: java.util.jar.JarException: file:/C:/Users/Desktop/XMLChangerTool/target/XMLChangerTool-1.0-SNAPSHOT.jar has unsigned entries - com/bmw/App.class
at javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:502)
at javax.crypto.JarVerifier.verifyJars(JarVerifier.java:363)
at javax.crypto.JarVerifier.verify(JarVerifier.java:289)
at javax.crypto.JceSecurity.verifyProviderJar(JceSecurity.java:164)
at javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:190)
at javax.crypto.Cipher.getInstance(Cipher.java:652)
所有库都添加为pom.xml文件中的依赖项。 pom看起来像这样
<dependencies>
<dependency>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
<version>140</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.bmw.App</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<mainClass>com.bmw.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
我是Security.removeProvider("BC")
Security.addProvider(new BouncyCastleProvider())
和security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider
,但无济于事。
甚至试图向Maven添加插件
,都没有成功也许有人知道我该如何解决这种情况?[尝试运行.jar文件时发生错误,原因是充气城堡库未签名或某种原因。线程“主”中的异常java.lang.SecurityException:JCE无法验证...
我不知道这是否是适合您的解决方案,但是我不得不将Bouncycastle Jars放在类路径的第一个位置,而不是其他jars上,然后签名异常消失了。奇怪的是,该异常仅发生在oracle jre上,没有采用openjdk。