web-push-libs / webpush-java

Web Push library for Java
MIT License
318 stars 112 forks source link

Generate Vapid Key Exception #82

Closed MuratKaragozgil closed 5 years ago

MuratKaragozgil commented 5 years ago

Hello,

I want to use generate vapid key method, but everytime i get these stacktrace on server. But I tried on my local machine, its working. I don't know what is different. (JDK and bouncycastyle version are same on local and server)

I have already tried different JDK and BouncyCastyle versions but nothing changed.

My code is here;

    GenerateKeyHandler generateKeyHandler = new GenerateKeyHandler(new GenerateKeyCommand());
    KeyPair vapidKeys = generateKeyHandler.generateKeyPair();

    ECPublicKey publicKey = (ECPublicKey) vapidKeys.getPublic();
    ECPrivateKey privateKey = (ECPrivateKey) vapidKeys.getPrivate();

    byte[] encodedPublicKey = Utils.encode(publicKey);
    byte[] encodedPrivateKey = Utils.encode(privateKey);

    String publicVapidKey = Base64Encoder.encodeUrl(encodedPublicKey);
    String privateVapidKey = Base64Encoder.encodeUrl(encodedPrivateKey);

Stacktrare is here ;

    at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyPairGeneratorSpi$EC.initialize(Unknown Source)
    at java.security.KeyPairGenerator.initialize(KeyPairGenerator.java:411)
    at nl.martijndwars.webpush.cli.handlers.GenerateKeyHandler.generateKeyPair(GenerateKeyHandler.java:63)
martijndwars commented 5 years ago
  1. To troubleshoot this problem, I'd need to see the full stack trace. Can you post this? The start of the stack trace should show which exception is being thrown.

  2. Alternatively, you can generate a key pair online at https://web-push-codelab.glitch.me/. This page generates a public- and private key and encodes them using base64. You can configure the Java library to use the base64 strings.

martijndwars commented 5 years ago

I'm closing this issue. Feel free to leave a comment if you still have an issue.