openssl (version 0.9.3)

ec_dh: Diffie-Hellman Key Agreement

Description

Key agreement is one-step method of creating a shared secret between two peers. Both peers can indendently derive the joined secret by combining his or her private key with the public key from the peer.

Usage

ec_dh(key = my_key(), peerkey, password = askpass)

Arguments

key
your own private key
peerkey
the public key from your peer
password
passed to read_key for reading protected private keys

Details

Currently only Elliptic Curve Diffie Hellman (ECDH) is implemented.

References

https://wiki.openssl.org/index.php/EVP_Key_Agreement, https://wiki.openssl.org/index.php/Elliptic_Curve_Diffie_Hellman

Examples

Run this code
# Need two EC keypairs from the same curve
sk1 <- ec_keygen()
pk1 <- as.list(sk1)$pubkey

sk2 <- ec_keygen()
pk2 <- as.list(sk2)$pubkey

# Both peers can derive the shared secret
alice <- ec_dh(sk1, pk2)
bob <- ec_dh(sk2, pk1)

Run the code above in your browser using DataCamp Workspace