<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CryptoKit",
  "identifier" : "/documentation/CryptoKit/SharedSecret",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Apple CryptoKit"
    ],
    "preciseIdentifier" : "s:9CryptoKit12SharedSecretV"
  },
  "title" : "SharedSecret"
}
-->

# SharedSecret

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

```
struct SharedSecret
```

## Overview

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`](/documentation/CryptoKit/SymmetricKey)) by itself. However, you use it to generate a key by
calling either the
[`hkdfDerivedSymmetricKey(using:salt:sharedInfo:outputByteCount:)`](/documentation/CryptoKit/SharedSecret/hkdfDerivedSymmetricKey(using:salt:sharedInfo:outputByteCount:)) or
[`x963DerivedSymmetricKey(using:sharedInfo:outputByteCount:)`](/documentation/CryptoKit/SharedSecret/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`](/documentation/CryptoKit/HMAC), or for opening and closing a sealed box with a cipher like
[`ChaChaPoly`](/documentation/CryptoKit/ChaChaPoly) or [`AES`](/documentation/CryptoKit/AES).

## Topics

### Deriving keys

[`hkdfDerivedSymmetricKey(using:salt:sharedInfo:outputByteCount:)`](/documentation/CryptoKit/SharedSecret/hkdfDerivedSymmetricKey(using:salt:sharedInfo:outputByteCount:))

Derives a symmetric encryption key from the secret using HKDF key
derivation.

[`x963DerivedSymmetricKey(using:sharedInfo:outputByteCount:)`](/documentation/CryptoKit/SharedSecret/x963DerivedSymmetricKey(using:sharedInfo:outputByteCount:))

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

### Comparing shared secrets

[`==(_:_:)`](/documentation/CryptoKit/SharedSecret/==(_:_:))

Determines whether a shared secret is equivalent to a collection of
contiguous bytes.

### Getting raw bytes

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`ContiguousBytes`](/documentation/Foundation/ContiguousBytes)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Copyable`](/documentation/Swift/Copyable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Sendable`](/documentation/Swift/Sendable)

[`Escapable`](/documentation/Swift/Escapable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)