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
sizeInBytesThe size of the key material in bytes.
initialzeIf
true, then the allocated memory will be filled cryptographically secure random data, else it will be filled with0xdb. -
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
bytesThe key material.
-
Creates another instance pointing to the same secure memory location.
Declaration
Swift
public init(_ other: KeyMaterial)Parameters
otherOther 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 -> ResultTypeParameters
bodyA code block where the key material is readable.
Return Value
The result from the
bodycode 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() -> BytesReturn Value
A copy of the key material.
View on GitHub
KeyMaterial Class Reference