19

Apple requests to its APNS must use JWT (JSON Web Token) signed using a Elliptic Curve Digital Signature Algorithm aka ECSDA using a p-256 curve and a SHA256 hash. How can you sign with such params in openssl?

openssl ecparam -list_curves

shows:

secp256k1 : SECG curve over a 256 bit prime field

prime256v1: X9.62/SECG curve over a 256 bit prime field
2
  • 1
    Nicolas - Did using prime256v1 work with Apple?
    – Raj
    Feb 7, 2020 at 21:58
  • 1
    yes it did work with apple servers Mar 6, 2021 at 20:03

1 Answer 1

24

The p-256 curve you want to use is prime256v1.

Try this:

Create private key:
openssl ecparam -genkey -name prime256v1 -noout -out private.pem

Create public key:
openssl ec -in private.pem -pubout -out public.pem

Sign something
openssl dgst -sha256 -sign private.pem yourinputdocument -out yourinput.sha256 yourinput 

To verify:
openssl dgst -sha256 -verify public.pem -signature yourinput.sha256 yourinputdocument
3
  • 2
    Megascolia - Could you explain why to use prime256v1 instead of secp256k1? I can sign using the key which has secp256k1 but Apple fails to verify the signature. Is it because of difference in libraries used to sign and verify ?
    – Raj
    Feb 7, 2020 at 21:53
  • 1
    I think the "sign something" line should have been: openssl dgst -sha256 -sign private.pem -out yourinput.sha256 yourinputdocument Sep 1, 2020 at 13:54
  • 3
    secp256k1 is deprecated and support has been removed from recent versions of openssl
    – kleptog
    Dec 9, 2021 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .