Hi.
I am trying to create a SecKey from my PKCS#8 key—the one generated for Sign in with Apple. But, I keep getting nil and the error "EC private key creation from data failed".
The following is the openssl command that I used to convert from p8 -> der:
I encoded the content of key.der to base64 using the following:
Code for creating a SecKey:
I am completely new to security, therefore I have limited knowledge on this topic. So far, the above code snippets are the ones I managed to research. But, I don't know what could be wrong with it.
Hoping someone could enlighten me on this security-related topic.
Thank you in advance!
I am trying to create a SecKey from my PKCS#8 key—the one generated for Sign in with Apple. But, I keep getting nil and the error "EC private key creation from data failed".
The following is the openssl command that I used to convert from p8 -> der:
Code Block openssl ec -in key.p8 -outform der -out key.der
I encoded the content of key.der to base64 using the following:
Code Block let utf8str = derContent.data(using: .utf8) if let base64Encoded = utf8str?.base64EncodedData(options: [.endLineWithLineFeed]) { print("keyBase64: \(String(data: base64Encoded, encoding: .utf8) ?? "NA")") }
Code for creating a SecKey:
Code Block let keyBase64 = "..." let keyData = Data(base64Encoded: keyBase64)! var error: Unmanaged<CFError>? let key = SecKeyCreateWithData(keyData as NSData, [ kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyClass: kSecAttrKeyClassPrivate ] as NSDictionary, &error)
I am completely new to security, therefore I have limited knowledge on this topic. So far, the above code snippets are the ones I managed to research. But, I don't know what could be wrong with it.
Hoping someone could enlighten me on this security-related topic.
Thank you in advance!