Structure

SymmetricKey

A symmetric cryptographic key.

Declaration

struct SymmetricKey

Overview

You typically derive a symmetric key from an instance of a shared secret (SharedSecret) that you obtain through key agreement. You use a symmetric key to compute a message authentication code like HMAC, or to open and close a sealed box (ChaChaPoly.SealedBox or AES.GCM.SealedBox) using a cipher like ChaChaPoly or AES.

Topics

Creating a Key

init<D>(data: D)

Creates a key from the given data.

init(size: SymmetricKeySize)

Generates a new random key of the given size.

struct SymmetricKeySize

The sizes that a symmetric cryptographic key can take.

Getting the Key Length

var bitCount: Int

The number of bits in the key.

Accessing Underlying Data

func withUnsafeBytes<R>((UnsafeRawBufferPointer) -> R) -> R

Invokes the given closure with a buffer pointer covering the raw bytes of the key.

Comparing Keys

static func == (SymmetricKey, SymmetricKey) -> Bool

Determines whether two symmetric keys are equal.

static func != (SymmetricKey, SymmetricKey) -> Bool

Determines whether two symmetric keys are not equal.

Relationships

See Also

Message Authentication Codes

struct HMAC

A hash-based message authentication algorithm.