Getting an Existing Key

Learn how to obtain an existing cryptographic key.

Overview

The Security framework defines the SecKey opaque type to hold key objects. You typically use a key reference to indicate the key to use for a particular cryptographic operation, such as encryption. How you get a key reference depends on where the key is stored. In particular, the source of a key might be one of the following:

  • Another key. When you have a private key, you can calculate the associated public key with the SecKeyCopyPublicKey(_:) function:

  • Data. You can export a key as a data blob that you can store on disk or send to someone else. Your app or another process can then do the reverse and restore the key from the data, possibly at a later time. See Storing Keys as Data for more details.

  • The keychain. You can place a key in a keychain to securely store it for later use. See Storing Keys in the Keychain for more details.