I wanted to follow up because I am having the same issue as the OP, and am able to successfully call SecKeyCreateWithData without error and receive a SecKeyRef. For my case, SecKeyCreateWithData seems to return different public/private keys for the same ck.dataRepresentation when called multiple times. For example, the following code block returns two different keys, and outputs different values:
let ck = try SecureEnclave.P256.Signing.PrivateKey()
let sf1 = try secCall { SecKeyCreateWithData(ck.dataRepresentation as NSData, [
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
] as NSDictionary, $0) }
let publicKey1 = SecKeyCopyPublicKey(sf1)!
let sf2 = try secCall { SecKeyCreateWithData(ck.dataRepresentation as NSData, [
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
] as NSDictionary, $0) }
let publicKey2 = SecKeyCopyPublicKey(sf2)!
print("Public1:\(publicKey1)")
print("Public2:\(publicKey2)")
Any ideas for why this may be the case?
Topic:
Privacy & Security
SubTopic:
General
Tags: