What is the right way to import a .p8 key? Getting DataError instead of success #423
-
I'm attempting to generate a JWT to use with Apple WeatherKit. Following their docs, I first download a private key from developer.apple.com. That downloads a .p8 file. I attempt to use it like so: // Copy the key from AuthKey.p8
const pkcs8 = `-----BEGIN PRIVATE KEY-----
my key here
-----END PRIVATE KEY-----`
const privateKey = await jose.importPKCS8(pkcs8, 'ES256') I believe the key is formatted correctly, as modifying it generates a different error that it must be a "PCKS8 formatted string". However, as it is, I get an error when calling TL;DR as the answer is in a reply thread, this doesn't work on Safari 15.5. You can try re-exporting as JWK and then importing that instead. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
That's a very rudimentary check just checking the input is a string and that the envelope is correct for a PKCS8 key. I am unfamiliar with what's inside apple's .p8 keys, so if you'd like more help, generate a fresh private key, paste it here, and then delete it because it's no longer going to be private. In essence, actual code to reproduce. |
Beta Was this translation helpful? Give feedback.
-
I am running into this unfortunately. Apple only exports p8 files now. Latest Safari is getting the same issue. Chrome seems fine. |
Beta Was this translation helpful? Give feedback.
That's a very rudimentary check just checking the input is a string and that the envelope is correct for a PKCS8 key.
I am unfamiliar with what's inside apple's .p8 keys, so if you'd like more help, generate a fresh private key, paste it here, and then delete it because it's no longer going to be private.
In essence, actual code to reproduce.