1

I wrote a small decryption tool using BouncyCastle. It works fine if i start it using the console.

java -jar Decryptor.jar

But if i launch it by double clicking the jar file the decryption fails with following exception:

Caused by: java.lang.SecurityException: JCE cannot authenticate the provider BC
at javax.crypto.Cipher.getInstance(Cipher.java:656)
at javax.crypto.Cipher.getInstance(Cipher.java:595)
at logdecryptor.Decryptor.getDecryptedPrivateKey(Decryptor.java:93)
... 60 more
Caused by: java.util.jar.JarException: file:/C:/***/Decryptor.jar has unsigned entries - decryptor/Main.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)
... 62 more

I am running on Windows 10, non-admin user and im not starting the jar file or the command line using admin permissions. Why does it behave differently depending on how i start it?

Edit:
It's a maven build. Here are my dependencies

   <dependency>
        <groupId>com.madgag.spongycastle</groupId>
        <artifactId>pkix</artifactId>
        <version>1.54.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.46</version>
    </dependency>

and here my plugins

<plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>decryptor.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

running with goals: clean compile assembly:single

Basti
  • 1,117
  • 12
  • 32
  • 1
    Where is the bouncycastle provider jar? – President James K. Polk Feb 18 '19 at 14:22
  • @JamesKPolk its a maven build with dependencies. I added the configurations. It dumps the jars content according to its package path into my jar. The resources are there since it works if i start it via cmd. I don't get why i tmakes a difference how you start it. Shouldn't double click also just start java.exe with the jar as a starting argument? – Basti Feb 18 '19 at 15:38
  • "It dumps the jars content according to its package path into my jar." That doesn't work for a signed jar, which is what the BC provider jar is. You have to leave the BC jar untouched and somewhere on the classpath. – President James K. Polk Feb 18 '19 at 17:16
  • @JamesKPolk But why would it work when launched from the command line but not by double-clicking the JAR file? The only difference I can think of is that double-clicking a JAR file typically uses `javaw` rather than `java`. – Slaw Feb 18 '19 at 17:30
  • 1
    @Slaw: I have no idea what the environment is, what the classpath environment variable says, etc. I only know you can't extract the contents of a signed jar and wrap into another jar since that will invalidate the signature. – President James K. Polk Feb 18 '19 at 19:25
  • @JamesKPolk well i was told that building a jar with dependencies does just exactly that. The envoirement is nothing special. Default jre/jdk8 installation, Project build with Maven and Intelli. Running on Windows 10. Pretty much nothing more to it. – Basti Feb 19 '19 at 07:11
  • @JamesKPolk Also ran it on some of my coworkers machines. Same issue. When run from console it works when run via double clicking it throws the exception. So its not just my system – Basti Feb 19 '19 at 15:14

0 Answers0