question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When I ran the encryption code with open jdk 1.8 it is all working fine. But when I am running with sun jdk jdk1.8.0_20, it is trowing following exception

Exception in thread "main" java.security.InvalidKeyException: Not an EC key: ECDH
    at sun.security.ec.ECKeyFactory.checkKey(ECKeyFactory.java:121)
    at sun.security.ec.ECKeyFactory.toECKey(ECKeyFactory.java:90)
    at sun.security.ec.ECDHKeyAgreement.engineInit(ECDHKeyAgreement.java:67)
    at javax.crypto.KeyAgreement.implInit(KeyAgreement.java:341)
    at javax.crypto.KeyAgreement.chooseProvider(KeyAgreement.java:373)
    at javax.crypto.KeyAgreement.init(KeyAgreement.java:465)
    at javax.crypto.KeyAgreement.init(KeyAgreement.java:436)
    at nl.martijndwars.webpush.HttpEce.deriveDH(HttpEce.java:117)
    at nl.martijndwars.webpush.HttpEce.deriveKey(HttpEce.java:54)
    at nl.martijndwars.webpush.HttpEce.encrypt(HttpEce.java:166)
    at nl.martijndwars.webpush.PushService.encrypt(PushService.java:62)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bsarkar6990commented, Nov 12, 2019

After some hit and trial I am able to resolve it.

Issue: When I was working with JDK 1.8 and bcprov-jdk15on-164.jar which is the latest bouncy castle for JDK 1.5 - JDK 1.11, it was working awesome. But bcprov-jdk15on-164.jar doesn’t work for JDK 1.7.0_80 and getting “java.security.InvalidKeyException: Not an EC key: ECDH” error.

Solution: While working with JDK 1.7.0_80 please use bcprov-jdk15to18-164.jar provider which is for JDK 1.5 - JDK 1.8.

0reactions
martijndwarscommented, Jun 8, 2017

I came across this issue as well when I created a fat JAR (a.k.a. uber JAR, shadow JAR). The BouncyCastle JAR is signed and if you create a fat JAR the contents of the BouncyCastle JAR are extracted and put in the fat JAR which breaks the signature. I suspect something similar was happening to you.

When I realised this I updated the build.gradle to exclude BouncyCastle from the fat JAR and add ../../lib/bcprov-jdk15on-154.jar to the Class-Path definition MANIFEST.MF. That way, when you run the generated fat JAR, it adds BouncyCastle to the classpath. Unfortunately, I had to commit lib/bcprov-jdk15on-154.jar into git.

In practice, developers will be using this project as a library and not as a fat JAR, so they will have to change their build to provide BouncyCastle at runtime. There are many ways to do this:

  1. Put bcprov-jdk15on-154.jar in $JAVA_HOME/jre/lib/ext, like you suggested. The downside of this approach is that if you need to repeat this if you update your JRE.
  2. Adapt the build system to add BouncyCastle at runtime (similar to how I adapted the gradle.build to add a Class-Path to the MANIFEST.MF). The downside is that you need to commit bcprov-jdk15on-154.jar into git.
  3. Use a custom class loader that is able to load nested JARs. That way you can put the BouncyCastle JAR in a fat JAR without breaking the signature. The downside is that you need to create and use a custom classloader (Spring Boot provides one, though).

I will update the README with instructions. Thanks for your investigation and feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Oracle Java SE Support Roadmap
Oracle provides this Oracle Java SE Support Roadmap, to help you understand maintenance and support options and related timelines.
Read more >
End of Service Life for Software Support (Sun Identity ...
Product Name Product Status Last Ship Date Phase 1(Full Supp... Sun Java System Identity Manager 7.1.1 Post RR May 15, 2009 May 15, 2010 Sun...
Read more >
FAQ - Sun Packages - Oracle
The classes in sun.* are present in the JDK to support Oracle's implementation of the Java platform: the sun.* classes are what make...
Read more >
Supported Software and Environments (Sun Identity Manager ...
Supported Software and Environments. This section lists software and environments that are compatible with Identity product software: Operating Systems.
Read more >
Platform Support and System Requirements (Sun Java ...
Sun Glass Fish Web Space Server (WSS) 10.0 Update 6 supports JDK 5 on Mac OS only, and not on Solaris, Linux, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found