<!--
{
  "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/P521/KeyAgreement/PrivateKey",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Apple CryptoKit"
    ],
    "preciseIdentifier" : "s:9CryptoKit4P521O12KeyAgreementO07PrivateD0V"
  },
  "title" : "P521.KeyAgreement.PrivateKey"
}
-->

# P521.KeyAgreement.PrivateKey

A P-521 private key used for key agreement.

```
struct PrivateKey
```

## Topics

### Creating a private key

[`init(compactRepresentable: Bool)`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/init(compactRepresentable:))

Creates a random P-521 private key for key agreement.

[`init<Bytes>(rawRepresentation: Bytes) throws`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/init(rawRepresentation:))

Creates a P-521 private key for key agreement from a collection of bytes.

[`init<Bytes>(derRepresentation: Bytes) throws`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/init(derRepresentation:))

Creates a P-521 private key for key agreement from a Distinguished Encoding
Rules (DER) encoded representation.

[`init(pemRepresentation: String) throws`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/init(pemRepresentation:))

Creates a P-521 private key for key agreement from a Privacy-Enhanced Mail
PEM) representation.

[`init<Bytes>(x963Representation: Bytes) throws`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/init(x963Representation:))

Creates a P-521 private key for key agreement from an ANSI x9.63
representation.

### Representing the key

[`var rawRepresentation: Data`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/rawRepresentation)

A data representation of the private key.

[`var derRepresentation: Data`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/derRepresentation)

A Distinguished Encoding Rules (DER) encoded representation of the private key.

[`var pemRepresentation: String`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/pemRepresentation)

A Privacy-Enhanced Mail (PEM) representation of the private key.

[`var x963Representation: Data`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/x963Representation)

An ANSI x9.63 representation of the private key.

### Finding the public key

[`var publicKey: P521.KeyAgreement.PublicKey`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/publicKey)

The corresponding public key.

### Creating a shared secret

[`func sharedSecretFromKeyAgreement(with: P521.KeyAgreement.PublicKey) throws -> SharedSecret`](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/sharedSecretFromKeyAgreement(with:))

Computes a shared secret with the provided public key from another party.

[`struct SharedSecret`](/documentation/CryptoKit/SharedSecret)

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

### Default Implementations

[DiffieHellmanKeyAgreement Implementations](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/DiffieHellmanKeyAgreement-Implementations)

[HPKEDiffieHellmanPrivateKeyGeneration Implementations](/documentation/CryptoKit/P521/KeyAgreement/PrivateKey/HPKEDiffieHellmanPrivateKeyGeneration-Implementations)

## Relationships

### Conforms To

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

[`DiffieHellmanKeyAgreement`](/documentation/CryptoKit/DiffieHellmanKeyAgreement)

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

[`HPKEDiffieHellmanPrivateKey`](/documentation/CryptoKit/HPKEDiffieHellmanPrivateKey)

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

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

[`HPKEDiffieHellmanPrivateKeyGeneration`](/documentation/CryptoKit/HPKEDiffieHellmanPrivateKeyGeneration)

---

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)