title: Native Method Error in KeyAgreement.generateSecret()
body: <p>I'm trying to generate a shared secret with javax.crypto.KeyAgreement:</p>
  
  <pre><code>public static byte[] generateSharedSecret(KeyPair localKeyPair, PublicKey clientPublicKey) {
      byte[] sharedSecret = {};
      try {
          KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH");
          keyAgreement.init(localKeyPair.getPrivate());
          keyAgreement.doPhase(clientPublicKey, true);
  
          sharedSecret = keyAgreement.generateSecret();
          MessageDigest hash = MessageDigest.getInstance("SHA-256");
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
      } catch (InvalidKeyException e) {
          e.printStackTrace();
      }
  
  
      return sharedSecret;
  }
  </code></pre>
  
  <p>but after running the program I give this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException
  at sun.security.ec.ECDHKeyAgreement.deriveKey(Native Method)
  at sun.security.ec.ECDHKeyAgreement.engineGenerateSecret(ECDHKeyAgreement.java:130)
  at javax.crypto.KeyAgreement.generateSecret(KeyAgreement.java:586)
  at io.softitecture.jpushup.keygen.ECDHKeyGenerator.generateSharedSecret(ECDHKeyGenerator.java:47)
  at io.softitecture.jpushup.payload.PayloadEncryptor.encrypt(PayloadEncryptor.java:19)
  at io.softitecture.App.main(App.java:15)
  </code></pre>
  
  <p>would you please help me out with this and tell me where I went wrong?</p>