Post

Replies

Boosts

Views

Activity

Create a SecKey from PKCS#8 (.p8 file)
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: openssl ec -in key.p8 -outform der -out key.der I encoded the content of key.der to base64 using the following: 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: 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!
4
0
2.7k
Jun ’20
Type does not conform to protocol 'PersistentModel'
I have the following and it's working. However, if I add a new String property, it suddenly returns the error above. This new property is added as a variable, initialized and conformed to hashable accordingly. @Model final class Car { var name: String var price: Double var remarks: String? var releaseDate: Date var brand: CarBrand init(name: String, price: Double, remarks: String?, releaseDate: Date, brand: CarBrand) { self.name = name self.price = price self.remarks = remarks self.releaseDate = releaseDate self.brand = brand } } extension Car: Identifiable {} extension Car: Hashable { static func == (lhs: Car, rhs: Car) -> Bool { lhs.name == rhs.name && lhs.price == rhs.price && lhs.remarks == rhs.remarks && lhs.releaseDate == rhs.releaseDate && lhs.brand == rhs.brand } func hash(into hasher: inout Hasher) { hasher.combine(name) hasher.combine(price) hasher.combine(remarks) hasher.combine(releaseDate) hasher.combine(brand) } } enum CarBrand: String, Codable, CaseIterable, Identifiable { case brandA case brandB case brandC var id: Self { self }
2
0
2.1k
Jun ’23