Create a SecKey from .p8 file

Hi,

I am trying to create a secKey from a .p8 file which I will then use to sign some data. I'm targeting an iOS application.

I understand I cannot use the p8 key directly with iOS APIs and will have to unwrap the p8 file before I can feed it to

SecKeyCreateWithData

I'm unsure how to go about doing it though and any help will be appreciated. For context it is the APNS p8 file.

Replies

First up, I recommend that you read On Cryptographic Key Formats.

If you can rely on Apple CryptoKit, you can:

  1. Import the PEM representation of the key using the init(pemRepresentation:) initialiser.

  2. Export the X9.63 representation using x963Representation.

  3. Create a SecKey form that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"