Hi,
I want to know the difference between private keys generated using Cryptokit framework and normal key pair generation.
Cryptokit framework documentation link is
https://developer.apple.com/documentation/cryptokit/performing_common_cryptographic_operations
Normal key pair generation link is
In both cases i am creating keys of type p256.
The sample code for both is given below.
//Private key using Cryptokit framework
let signinKey = P256.Signing.PrivateKey()
//Private key using normal keypair generation
let attributes: [String: Any] = [
kSecClass as String: kSecClassKey,
kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom,
kSecAttrKeySizeInBits as String: 256,
kSecPrivateKeyAttrs as String: [
kSecAttrIsPermanent as String: true,
kSecAttrLabel as String:"test",
kSecAttrAccessible: kSecAttrAccessibleWhenUnlocked,
kSecUseDataProtectionKeychain: true,
kSecAttrApplicationTag as String: "com.mydomian.uniqueTag" ]
]
var error: Unmanaged<CFError>?
guard let privateKey = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
Thanks in Advance for the help
The error log i am getting is -34018
This problem is almost certainly caused by you testing in a playground, which is missing the
com.apple.application-identifier entitlement. You can the background to this in
Troubleshooting -34018 Keychain Errors.
I recommend that you test in an app. If you’re targeting iOS, that should be sufficient. If you’re targeting macOS, you need to make sure you have the
com.apple.application-identifier, which you don’t get by default. I usually trigger this by enabling keychain sharing but then don’t list any shared groups.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"