I'm trying to create an app with the public-key encryption, so I need to add a private key to the keychain but I don't really know how to do it. Please help me)
How to add Curve25519.Signing.PrivateKey() to the keychain?
Hi,
usually you would do it by storing the data representation of the key like this (working code, beta 3):
let key = P256.Signing.PrivateKey()
let keyData = key.x963Representation
// Store the data in the key chain
print("--- Org Key data ---")
print(keyData.base64EncodedString())
// Load the data from the keychain
let keyFromData = try? P256.Signing.PrivateKey(x963Representation: keyData)
if let keyFromData = keyFromData {
print("--- Loaded Key data ---")
print(keyFromData.x963Representation.base64EncodedString())
}But it it looks like that Curve25519 does not support key data represntation yet. Maybe this will come in a later Beta.