Last active
October 17, 2022 23:43
-
-
Save cardosoedgar/8528d50c49dbcb595e47d2df0c9674c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generateSecureEnclaveKey() -> SecKey? { | |
let attributes: [String: Any] = [ | |
// key id | |
kSecAttrApplicationTag as String: "com.cardosoedgar.key", | |
// key size | |
kSecAttrKeySizeInBits as String: 256, | |
// key type | |
kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom, | |
// attribute to specify this key should be stored on Secure Enclave | |
kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave | |
] | |
var error: Unmanaged<CFError>? | |
guard let ref = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else { | |
print(error.debugDescription) | |
return nil | |
} | |
return ref | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment