Java JCE 无法在 jarsplice 创建的 jar 中验证提供者 BC

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22160780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:58:48  来源:igfitidea点击:

Java JCE cannot authenticate provider BC in jarsplice created jar

javasecurityexception

提问by Spencer H

I am working on a game and I am using the Slick2D library. I am also using bouncycastle for encryption. Then I use jarsplice to package everything together in a nice executable. And it runs fine until it needs to encrypt something. It gives me a java.lang.SecurityException: JCE cannot authenticate the provider BCAnd I am using a signed jarfile (http://www.bouncycastle.org/download/bcprov-jdk15on-150.jar)

我正在开发一款游戏,并且正在使用 Slick2D 库。我也在使用 bouncycastle 进行加密。然后我使用 jarsplice 将所有内容打包到一个不错的可执行文件中。它运行良好,直到需要加密某些东西。它给了我一个java.lang.SecurityException: JCE cannot authenticate the provider BC我正在使用签名的 jarfile ( http://www.bouncycastle.org/download/bcprov-jdk15on-150.jar)

Here is the stack trace

这是堆栈跟踪

 java.lang.SecurityException: JCE cannot authenticate the provider BC
    at javax.crypto.Cipher.getInstance(Cipher.java:642)
    at javax.crypto.Cipher.getInstance(Cipher.java:580)
    at net.matrixstudios.zenerith.networking.ZenerithLogin.encryptLogin(ZenerithLogin.java:159)
    at net.matrixstudios.zenerith.networking.ZenerithLogin.<init>(ZenerithLogin.java:112)
    at net.matrixstudios.zenerith.MultiplayerMenu.performAction(MultiplayerMenu.java:90)
    at net.matrixstudios.zenerith.gui.menu.MenuGameState.clickButton(MenuGameState.java:83)
    at net.matrixstudios.zenerith.gui.menu.MenuGameState.checkForButtonClicks(MenuGameState.java:75)
    at net.matrixstudios.zenerith.gui.menu.MenuGameState.update(MenuGameState.java:51)
    at net.matrixstudios.zenerith.gui.menu.AbstractGameState.update(AbstractGameState.java:47)
    at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:266)
    at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
    at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
    at net.matrixstudios.zenerith.gui.Window.<init>(Window.java:28)
    at net.matrixstudios.Main.main(Main.java:28)
Caused by: java.util.jar.JarException: file:/C:/Users/M4trixSh4d0w/Desktop/Zenerith_Alpha.0.2.1.5.jar has unsigned entries - org/bouncycastle/LICENSE.class
    at javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:462)
    at javax.crypto.JarVerifier.verifyJars(JarVerifier.java:322)
    at javax.crypto.JarVerifier.verify(JarVerifier.java:250)
    at javax.crypto.JceSecurity.verifyProviderJar(JceSecurity.java:161)
    at javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:187)
    at javax.crypto.Cipher.getInstance(Cipher.java:638)
    ... 14 more

So how do I authenticate the jarfile to run? This is a standalone executable jarfile.

那么如何验证要运行的 jarfile 呢?这是一个独立的可执行 jarfile。

采纳答案by unigeek

You probably want to register the cryptographic service provider at runtime to ensure the configuration will work for everyone. You can use either of the Security.addProvider() or Security.insertProviderAt() methods. See documentation linked below under "Managing Providers".

您可能希望在运行时注册加密服务提供者,以确保配置适用于所有人。您可以使用 Security.addProvider() 或 Security.insertProviderAt() 方法。请参阅下面“管理提供商”下链接的文档。

Just use addProvider() unless the order of providers is somehow important for you. I saw one contributor commented that you might slot it in at entry #9, but I didn't see evidence that this is right for your configuration, so probably just an extraneous detail from his/her config file. Obviously, if I missed something about your configuration and you do need it there, then go for insertProviderAt().

除非提供者的顺序对您来说很重要,否则只需使用 addProvider() 。我看到一位贡献者评论说您可能会将它插入到条目 #9,但我没有看到证据表明这适合您的配置,所以可能只是他/她的配置文件中的一个无关紧要的细节。显然,如果我遗漏了有关您的配置的某些内容而您确实需要它,那么请使用 insertProviderAt()。