Skip to content

Key Agreement

Alina P edited this page Feb 25, 2025 · 3 revisions

πŸ”‘ What is Key Agreement?

Key Agreement (ECDH) is used to securely generate a shared secret between two parties. This secret is then used for key derivation and encryption.

Important

Curves of a private and a public keys supposed to be of the same type

Supported Curves

  • P256
  • P384
  • P521
  • Curve25519

πŸš€ Generate a Shared Secret

let privateKey = P256.KeyAgreement.PrivateKey()
let publicKey = privateKey.publicKey

let sharedSecret = try M_AES_GCM_HKDF.getSharedSecret(privateKey: privateKey, publicKey: publicKey)

Also it can work with the SecKey that has under known Curves

let privateKey: SecKey
let publicKey: SecKey
let sharedSecret = try M_AES_GCM_HKDF.getSharedSecret(privateKey: privateKey, publicKey: publicKey)

Clone this wiki locally