Closed ghost closed 8 years ago
Can you provide a little bit more context, a little sample code that fails? I telling that because it there are unit test for rsa/dsa https://github.com/funcool/buddy-sign/blob/master/test/buddy/sign/jws_tests.clj#L132 that passes properly.
Here is my minimal example:
(ns backend.utils.jwt
(:require
[clojure.java.io :as io]
[clj-time.core :as t]
[buddy.sign.jws :as jws]
[buddy.core.keys :as keys]))
(defn- private-key []
(keys/private-key
(io/resource "keys/ecprivkey.pem")))
(defn- public-key []
(keys/public-key
(io/resource "keys/ecpubkey.pem")))
(defn new-token
[res]
(let [exp (t/plus (t/now) (t/days 1))]
(jws/sign res (private-key) {:exp exp})))
(defn from-token
[token]
(try
(jws/unsign token (public-key))
(catch Exception e
(do (prn e)
nil
))))
(comment
(def token (new-token {:foo "bar"}))
(jws/unsign token (pubkey))
)
I hope there is no problem in conflicted deps, I have :pedantic? :abort
on in my project.clj
.
If I add custom alg when signing ( {:alg :es512}
, I got his error when I unsign :
IllegalArgumentException No matching method found: initVerify for class java.security.Signature$Delegate clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
I have missing specify the algoriththm:
(jws/sign res (private-key) {:alg :es256 :exp exp})))
Using just your code and replacing the paths of the key pair and adding the :es256
or :es512
algorithm it just works.
yeah, I think it should work too. I doubt there are deps conflictions in my code base. hmm
You have been able to solve the problem?
@niwinz I haven't retried it yet, work on another task. I will retry soon and report the results.
I think there is something wrong with my project, I'm not sure, I don't have time to debug the problem yet. But copying the example from you, everything works fine now. Thanks for helping :)
Nice to know! Thanks!
I got this error while trying to sign resource with dsa and rsa keys: