# innovaphone.crypto.ecdh

Example: Alice and Bob want to agree on a shared secret over an insecure channel. For that they use an ECDH key agreement.

- Alice and Bob create their private key.
- Then both create a public key share that they can send to each other over an insecure channel.
- Finally both use it to calculate the same shared secret.

// Alice's private key var alice = new innovaphone.crypto.ecdh(); // Alice's public key share var alicesKeyShare = alice.getLocalKeyShare(); // Bob's private key var bob = new innovaphone.crypto.ecdh(); // Bob's public key share var bobsKeyShare = bob.getLocalKeyShare(); // Shared secret calculated by Alice var alicesSharedSecret = alice.getSharedSecret(bobsKeyShare); // Shared secret calculated by Bob var bobsSharedSecret = bob.getSharedSecret(alicesKeyShare); document.getElementById("out").innerHTML += "<br>" + "alicesKeyShare=" + "<br>" + alicesKeyShare; document.getElementById("out").innerHTML += "<br>" + "bobsKeyShare=" + "<br>" + bobsKeyShare; document.getElementById("out").innerHTML += "<br>" + "alicesSharedSecret=" + "<br>" + alicesSharedSecret; document.getElementById("out").innerHTML += "<br>" + "bobsSharedSecret=" + "<br>" + bobsSharedSecret;

## innovaphone.crypto.ecdh

A class for ECDH key agreement.

innovaphone.crypto.ecdh(curve, includePointFormat)
  A constructor for the object encapsulating a single ECDH handshake.
  curve
    Optional, defaulting to "secp256r1". The elliptic curve that shall be used. Allowed values are "secp256r1", "secp224r1", "secp192r1", "secp192k1", "secp160r1", "secp160k1" and "secp128r1".
  includePointFormat
    Optional, defaulting to false. If set to true the key shares include a prefix specifying the point format "04".
getLocalKeyShare()
  Returns a hexstring representing the local key share.
getSharedSecret(remoteKeyShare)
  Takes the remote key share and returns the shared secret as a hexstring.
  remoteKeyShare
    A hexstring representing the remote key share.