<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CryptoKit",
  "identifier" : "/documentation/CryptoKit/P521/KeyAgreement/PublicKey/hpkeRepresentation(kem:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Apple CryptoKit",
      "CryptoKit"
    ],
    "preciseIdentifier" : "s:9CryptoKit4P521O12KeyAgreementO06PublicD0V18hpkeRepresentation3kem10Foundation4DataVAA4HPKEO3KEMO_tKF"
  },
  "title" : "hpkeRepresentation(kem:)"
}
-->

# hpkeRepresentation(kem:)

Creates a serialized representation of the public key.

```
func hpkeRepresentation(kem: HPKE.KEM) throws -> Data
```

## Return Value

The serialized representation of the public key.

## Discussion

- kem: The Key Encapsulation Mechanism to use with the public key.

> Throws: ``doc://com.apple.CryptoKit/documentation/CryptoKit/HPKE/Errors/inconsistentCiphersuiteAndKey`` if the key encapsulation mechanism requested is incompatible with this public key.

---

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)