One Logo Pool Ball
CryptoKit · IOS API REFERENCE

HPKE.Sender

struct · iOS 17.0+ · SDK 27.1

struct Sender

A type that represents the sending side of an HPKE message exchange. To create encrypted messages, initialize a `Sender` specifying the appropriate cipher suite, the recipient's public key, and the additional cryptographic material relevant to your chosen mode of operation. Call ``seal(_:)`` or ``seal(_:authenticating:)`` on the `Sender` instance for each message in turn to retrieve its ciphertext. The recipient of the messages needs to process them in the same order as the `Sender`, using the same encryption mode, cipher suite, and key schedule information (`info`), as well as the `Sender`'s ``encapsulatedKey``.

Members (5)

method · iOS 17.0+

exportSecret

TypeScript
exportSecret(context: ArrayBuffer, outputByteCount: number): SymmetricKey
Swift declaration
func exportSecret<Context>(context: Context, outputByteCount: Int) throws -> SymmetricKey where Context : DataProtocol

Exports a secret given domain-separation context and the desired output length. - Parameters: - context: Application-specific information providing context on the use of this key. - outputByteCount: The desired length of the exported secret. - Returns: The exported secret.

init · iOS 26.0+

init

TypeScript
static init(recipientKey: XWingMLKEM768X25519_PublicKey, ciphersuite: HPKE_Ciphersuite, info: ArrayBuffer): HPKE_Sender
Swift declaration
init<PK>(recipientKey: PK, ciphersuite: HPKE.Ciphersuite, info: Data) throws where PK : HPKEKEMPublicKey

Creates a sender in base mode. The `Sender` encrypts messages in base mode with a symmetric encryption key it derives using a key derivation function (KDF). The KDF uses the key schedule data in `info` as input to generate the key. The `Sender` encapsulates the derived key using the recipient's public key. You access the encapsulated key using ``encapsulatedKey``. - Parameters: - recipientKey: The recipient's public key for encrypting the messages. - ciphersuite: The cipher suite that defines the cryptographic algorithms to use. - info: Data that the key derivation function uses to compute the symmetric key material. The sender and the recipient need to use the same `info` data. - Note: The system throws errors from ``CryptoKit/HPKE/Errors`` when it encounters them.

get · iOS 17.0+

encapsulatedKey

TypeScript
get encapsulatedKey(): ArrayBuffer
Swift declaration
let encapsulatedKey: Data

The encapsulated symmetric key that the recipient uses to decrypt messages.

method · iOS 17.0+

seal

TypeScript
sealAuthenticating(msg: ArrayBuffer, aad: ArrayBuffer): ArrayBuffer
Swift declaration
mutating func seal<M, AD>(_ msg: M, authenticating aad: AD) throws -> Data where M : DataProtocol, AD : DataProtocol

Encrypts the given cleartext message and attaches additional authenticated data. You can call this method multiple times to encrypt a series of messages. When using this method, you need to supply ciphertext messages to the decryption code on the receiving side in the same order as you encrypt them. - Parameters: - msg: The cleartext message to encrypt. - aad: Additional data that the `Sender` authenticates and adds to the message in cleartext. - Note: The system throws errors from ``CryptoKit/HPKE/Errors`` when it encounters them. - Returns: The ciphertext for the recipient to decrypt.

method · iOS 17.0+

seal

TypeScript
seal(msg: ArrayBuffer): ArrayBuffer
Swift declaration
mutating func seal<M>(_ msg: M) throws -> Data where M : DataProtocol

Encrypts the given cleartext message. You can call this method multiple times to encrypt a series of messages. When using this method, you need to supply ciphertext messages to the decryption code on the receiving side in the same order as you encrypt them. - Parameters: - msg: The cleartext message to encrypt. - Note: The system throws errors from ``CryptoKit/HPKE/Errors`` when it encounters them. - Returns: The ciphertext for the recipient to decrypt.

Skipped declarations

4 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

HPKE.Sender.init(recipientKey:ciphersuite:info:)

This declaration needs Swift generic type arguments. (no canonical witness for PK)

HPKE.Sender.init(recipientKey:ciphersuite:info:presharedKey:presharedKeyIdentifier:)

This declaration needs Swift generic type arguments. (no canonical witness for PK)

HPKE.Sender.init(recipientKey:ciphersuite:info:authenticatedBy:)

This declaration needs Swift generic type arguments. (no canonical witness for SK.PublicKey)

HPKE.Sender.init(recipientKey:ciphersuite:info:authenticatedBy:presharedKey:presharedKeyIdentifier:)

This declaration needs Swift generic type arguments. (no canonical witness for SK.PublicKey)

All CryptoKit types →