Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class KeyAgreement

  1. Object
  2. KeyAgreement

Elliptic-curve Diffie-Hellman key agreement over P-256.

Two parties that each hold a key pair from KeyGenerator.ec(int) exchange public keys; each combines its own private key with the other’s public key and both arrive at the same secret, which no one watching the exchange can compute. That secret is not a key yet – run it through Hkdf first.

KeyPair alice = KeyGenerator.ec(256);
KeyPair bob = KeyGenerator.ec(256);
byte[] a = KeyAgreement.ecdh(alice.getPrivateKey(), bob.getPublicKey());
byte[] b = KeyAgreement.ecdh(bob.getPrivateKey(), alice.getPublicKey());
// a and b hold the same 32 bytes

The computation runs in the platform’s native crypto provider.

Methods

public static byte[] ecdh(PrivateKey mine, PublicKey theirs)Computes the ECDH shared secret: the 32-byte x coordinate of the product of mine and theirs, as SEC 1 and the JCA define it.

Inherited methods

Method details

ecdh

public static byte[] ecdh(PrivateKey mine, PublicKey theirs)
Computes the ECDH shared secret: the 32-byte x coordinate of the product of mine and theirs, as SEC 1 and the JCA define it.

Parameters

mine PrivateKey
this side’s EC private key
theirs PublicKey
the other side’s EC public key

Throws

CryptoException
if either key is not a P-256 key, or the public key is not a point on the curve