KeyExchange

public class KeyExchange

A class that can be used for exchanging keys between two parties on an adverserial channel.

Example

let alice = KeyExchange(side: .client)
let bob = KeyExchange(side: .server)

let alicesSessionKey = alice.sessionKey(for: bob.publicKey)
let bobsSessionKey = bob.sessionKey(for: alice.publicKey)

// alicesSessionKey == bobsSessionKey
  • The side of the key exchange.

    See more

    Declaration

    Swift

    public enum Side
  • The public key used for the key exchange mechanism.

    See more

    Declaration

    Swift

    public class PublicKey : KeyMaterial
  • The session key, that can be used for encryption after a successful key exchange.

    Declaration

    Swift

    public class SessionKey : KeyMaterial
  • A session key pair.

    See more

    Declaration

    Swift

    public struct SessionKeyPair
  • The side of the key exchange.

    Declaration

    Swift

    public let side: Side
  • The public key.

    Declaration

    Swift

    public let publicKey: PublicKey
  • Initializes the local part of a key exchange.

    Declaration

    Swift

    public init(side: Side)

    Parameters

    side

    The side of the key exchange.

  • Exchanges a session key pair with another party.

    Note

    If this party is the client side, the other party needs to be the server side vice versa.

    Declaration

    Swift

    public func sessionKeys(for otherPublicKey: PublicKey) -> SessionKeyPair?

    Parameters

    otherPublicKey

    The public key of the other party.

    Return Value

    The session key pair on success and nil if the public key of the other party is not acceptable.

  • Exchanges a single key with another party.

    Note

    If this party is the client side, the other party needs to be the server side vice versa.

    Declaration

    Swift

    public func sessionKey(for otherPublicKey: PublicKey) -> SessionKey?

    Parameters

    otherPublicKey

    The public key of the other party.

    Return Value

    The session key on success and nil if the public key of the other party is not acceptable.