1

I'm trying to create a JWT with joken

privKey = """
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIPaIrqi+I+znfdsteEXELr2J1e+qC72KNam6fx40pYvi
-----END PRIVATE KEY-----
"""

signer = Joken.Signer.create("Ed25519", %{"pem" => privKey})

Joken.generate_and_sign!(%{}, %{"name" => "John Doe"}, signer)

I receive the error

** (FunctionClauseError) no function clause matching in :jose_jwk_kty_ec.parameters_to_crv/1    
    
    The following arguments were given to :jose_jwk_kty_ec.parameters_to_crv/1:
    
        # 1
        :ed25519
    
    (jose 1.11.2) src/jwk/jose_jwk_kty_ec.erl:410: :jose_jwk_kty_ec.parameters_to_crv/1
    (jose 1.11.2) src/jwk/jose_jwk_kty_ec.erl:389: :jose_jwk_kty_ec.jws_alg_to_digest_type/2
    (jose 1.11.2) src/jwk/jose_jwk_kty_ec.erl:199: :jose_jwk_kty_ec.sign/3
    (jose 1.11.2) src/jws/jose_jws.erl:311: :jose_jws.sign/4
    (jose 1.11.2) src/jwt/jose_jwt.erl:173: :jose_jwt.sign/3
    (joken 2.5.0) lib/joken/signer.ex:128: Joken.Signer.sign/2
    (joken 2.5.0) lib/joken.ex:361: Joken.encode_and_sign/3
    iex:6: (file)

What is causing the error, I had a look at the code on https://github.com/joken-elixir/joken/issues/214 to try and fix it but couldn't.

jps
  • 20,041
  • 15
  • 75
  • 79
Tarang
  • 75,157
  • 39
  • 215
  • 276
  • Is that private key correct? `ssh-keygen -t ed25519` produces a 7-line PEM file. – Adam Millerchip Nov 15 '22 at 01:02
  • Its created using openssl `openssl genpkey -algorithm ED25519 -out ed25519.key.pem` – Tarang Nov 17 '22 at 04:01
  • why not using the `outform ` arg? like `openssl genpkey -algorithm ed25519 -outform PEM -out private.pem` – ymz Nov 29 '22 at 19:48
  • @ymz i think the output of both are equivalent, the keys from both have the same issue and are in the same format – Tarang Nov 30 '22 at 10:32
  • It looks like the Jose library may not handle ED25519 for now, see here: https://github.com/joken-elixir/joken/blob/fe5cd7201f586204edde3a121a3ef47e194684ae/test/joken_signer_test.exs#L7-L19 – SmoothBrane Nov 30 '22 at 22:51
  • ...but should be added in 1.12 https://github.com/potatosalad/erlang-jose/pull/123#event-7305372542 – SmoothBrane Nov 30 '22 at 23:02

0 Answers0