Swift: Storing key pairs in the keyring
In my last blog post I described how to generate public/private key pairs in Swift and use them to encrypt and decrypt text. But that’s not entirely useful in its own unless you have a place to store the pairs, such as the iOS keychain.
Eagle-eyed readers may have also noticed that I skipped one important detail when discussing generating keys:
var publicKeyPtr, privateKeyPtr: Unmanaged<SecKey>? result = SecKeyGeneratePair(parameters, &publicKeyPtr, &privateKeyPtr)
I never specified the
parameters dictionary anywhere.
Unfortunately this involves wading into the murkier parts of the compatibility between Swift, Foundation and Core Foundation: the compatibility between the different array and dictionary types, and the different type strictness required for protocol conformance.
Consider the basic dictionary that we would pass for a 2048-bit RSA key:
Continue reading →