KeyMaterial

public class KeyMaterial

This class can be used to securely store key material in memory.

  • The size of the key material in bytes.

    Declaration

    Swift

    public var sizeInBytes: UInt32 { get }
  • Initializes new key material of a given size.

    Declaration

    Swift

    public init(sizeInBytes: UInt32, initialize: Bool = true)

    Parameters

    sizeInBytes

    The size of the key material in bytes.

    initialze

    If true, then the allocated memory will be filled cryptographically secure random data, else it will be filled with 0xdb.

  • Initializes key material by a given byte array. The byte array is copied to a secure memory location and overwritten with zeros afterwards in order to avoid the key material from being compromised.

    Declaration

    Swift

    public init?(bytes: inout Bytes)

    Parameters

    bytes

    The key material.

  • Creates another instance pointing to the same secure memory location.

    Declaration

    Swift

    public init(_ other: KeyMaterial)

    Parameters

    other

    Other key material.

  • Read raw bytes from the key material.

    Usually you do not need to call this function.

    Declaration

    Swift

    public func withUnsafeBytes<ResultType, ContentType>(body: (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType

    Parameters

    body

    A code block where the key material is readable.

    Return Value

    The result from the body code block.

  • Copy the key material from the secure memory into an insecure byte array.

    Warning

    Use this with caution, as the output is not located in secure memory.

    Declaration

    Swift

    @inline(__always)
    public func copyBytes() -> Bytes

    Return Value

    A copy of the key material.