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.

java.security.InvalidKeyException: Not an EC key: ECDH

See original GitHub issue

I’m getting this error using the CLI send-notification 👍

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:346)
        at javax.crypto.KeyAgreement.chooseProvider(KeyAgreement.java:378)
        at javax.crypto.KeyAgreement.init(KeyAgreement.java:470)
        at javax.crypto.KeyAgreement.init(KeyAgreement.java:441)
        at webpush.HttpEce.extractDH(HttpEce.java:360)
        at webpush.HttpEce.extractSecretAndContext(HttpEce.java:229)
        at webpush.HttpEce.deriveKeyAndNonce(HttpEce.java:256)
        at webpush.HttpEce.encrypt(HttpEce.java:70)
        at webpush.PushService.encrypt(PushService.java:94)
        at webpush.PushService.preparePost(PushService.java:179)
        at webpush.PushService.sendAsync(PushService.java:150)
        at webpush.PushService.send(PushService.java:132)
        at webpush.PushService.send(PushService.java:136)
        at webpush.cli.handlers.SendNotificationHandler.run(SendNotificationHandler.java:27)
        at webpush.cli.Cli.main(Cli.java:43)

any idea what could cause this ? (I checked all parameters)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Ersmipecommented, Sep 20, 2021

I have the same issue as OP. When I run the same code with same vapid locally, everything works (only once appeared exception mentioned in original post). When I run it on the server, this exception appears every time code tries to send notification. I think there could be issue with some incompatible overlapping dependencies, but I’ll have to do some further investigation.

0reactions
wwwAirucommented, Sep 5, 2022

I tried using openjdk 13 and the problem went away, but I didn’t understand why it throws an exception on jdk 17

Read more comments on GitHub >

github_iconTop Results From Across the Web

InvalidKeyException using ECPublicKey - Stack Overflow
I'm getting the following exception when i try to encrypt a byte array with a EC public key :
Read more >
Bug ID: JDK-8261502 ECDHKeyAgreement
A DESCRIPTION OF THE PROBLEM : After updating from OpenJDK 13.0.2 to OpenJDK 15.0.2 our code that generates an ECDH key agreement fails...
Read more >
ECDH - nimbus-jose-jwt 6.4 javadoc
InvalidKeyException ; 023import java.security. ... i.e. the consumer's public EC 144 * key on encryption, or the ephemeral public EC key 145 *...
Read more >
KeyGenParameterSpec - Android Developers
Example: EC key for ECDH key agreement. This example illustrates how to generate an elliptic curve key pair, used to establish a shared...
Read more >
src/share/classes/sun/security/pkcs11/P11ECKeyFactory.java
else if (key instanceof ECPublicKey) { ECPublicKey ecKey ... should never occur throw new InvalidKeyException ("Key class not yet supported: " + key....
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