Structure

SharedSecret

A key agreement result from which you can derive a symmetric cryptographic key.

Declaration

struct SharedSecret

Overview

You generate a shared secret by calling your private key’s sharedSecretFromKeyAgreement(publicKeyShare:) method with the public key from another party. The other party computes the same secret by passing your public key to the the equivalent method on their own private key.

The shared secret isn’t suitable as a symmetric cryptographic key (SymmetricKey) by itself. However, you use it to generate a key by calling either the hkdfDerivedSymmetricKey(using:salt:sharedInfo:outputByteCount:) or x963DerivedSymmetricKey(using:sharedInfo:outputByteCount:) method of the shared secret. After the other party does the same, then you both share a symmetric key suitable for creating a message authentication code like HMAC, or for opening and closing a sealed box (AEADSealedBox) with a cipher like ChaChaPoly or AES.

Topics

Deriving Keys

func x963DerivedSymmetricKey<H, SI>(using: H.Type, sharedInfo: SI, outputByteCount: Int) -> SymmetricKey

Derives a symmetric encryption key from the secret using x9.63 key derivation.

struct SymmetricKey

A symmetric cryptographic key.

Comparing Shared Secrets

static func == (SharedSecret, SharedSecret) -> Bool

Returns a Boolean indicating whether two shared secrets are equal.

static func != (SharedSecret, SharedSecret) -> Bool

Returns a Boolean indicating whether two shared secrets are not equal.

Describing the Secret

var description: String

A human readable description of the secret.

Hashing the Secret

func hash(into: inout Hasher)

Hashes the essential components of the shared secret by feeding them into the given hasher.

var hashValue: Int

The hash value of the shared secret.

Getting Raw Bytes

func withUnsafeBytes<R>((UnsafeRawBufferPointer) -> R) -> R

Invokes the given closure with a buffer pointer covering the raw bytes of the shared secret.

See Also

Public-Key Cryptography

enum Curve25519

An elliptic curve that enables X25519 key agreement and ed25519 signatures.

Beta
enum P521

An elliptic curve that enables NIST P-521 signatures and key agreement.

Beta
enum P384

An elliptic curve that enables NIST P-384 signatures and key agreement.

Beta
enum P256

An elliptic curve that enables NIST P-256 signatures and key agreement.

Beta
enum SecureEnclave

A representation of a device’s hardware-based key manager.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software