Key

public class Key : KeyMaterial

This class represents a key that can be used for hashing.

  • The minimum size of the key in bytes.

    Declaration

    Swift

    public static let MinimumSizeInBytes: UInt32
  • The maximum size of the key in bytes.

    Declaration

    Swift

    public static let MaximumSizeInBytes: UInt32
  • The default key size in bytes.

    Declaration

    Swift

    public static let DefaultSizeInBytes: UInt32
  • Initialize a new key with a given size.

    The size needs to be within the given bounds: MinimumSizeInBytessizeInBytesMaximumSizeInBytes.

    Declaration

    Swift

    public init?(sizeInBytes: UInt32)

    Parameters

    sizeInBytes

    The size of the key in bytes.

  • Initialize a new key with the default size.

    Declaration

    Swift

    public convenience init()
  • Restores a key from a given byte array. The byte array is copied to a secure location and overwritten with zeroes to avoid the key being compromised in memory.

    Warning

    Do not initialize new keys with this function. If you need a new key, use init?(sizeInBytes:) instead. This initializer is only to restore secret keys that were persisted.

    Declaration

    Swift

    public override init?(bytes: inout Bytes)

    Parameters

    bytes

    The key.

  • Restores a key from a given hex string.

    Warning

    Do not initialize new keys with this function. If you need a new key, use init?(sizeInBytes:) instead. This initializer is only to restore secret keys that were persisted.

    See

    Data(hex:ignore:)

    Declaration

    Swift

    public convenience init?(hex: String, ignore: String? = nil)

    Parameters

    hex

    The key as a hex encoded string.

    ignore

    A character set that should be ignored when decoding the key.