Class KeyAgreement
java.lang.Object
com.codename1.security.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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]ecdh(PrivateKey mine, PublicKey theirs) Computes the ECDH shared secret: the 32-byte x coordinate of the product ofmineandtheirs, as SEC 1 and the JCA define it.
-
Method Details
-
ecdh
Computes the ECDH shared secret: the 32-byte x coordinate of the product of
mineandtheirs, as SEC 1 and the JCA define it.Parameters
-
mine: this side's EC private key -
theirs: 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
-
-