Giter VIP home page Giter VIP logo

Comments (9)

niwinz avatar niwinz commented on August 27, 2024

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.

from buddy-sign.

0xqd avatar 0xqd commented on August 27, 2024

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)

from buddy-sign.

niwinz avatar niwinz commented on August 27, 2024

I have missing specify the algoriththm:

(jws/sign res (private-key) {:alg :es256 :exp exp})))

from buddy-sign.

niwinz avatar niwinz commented on August 27, 2024

Using just your code and replacing the paths of the key pair and adding the :es256 or :es512 algorithm it just works.

from buddy-sign.

0xqd avatar 0xqd commented on August 27, 2024

yeah, I think it should work too. I doubt there are deps conflictions in my code base. hmm

from buddy-sign.

niwinz avatar niwinz commented on August 27, 2024

You have been able to solve the problem?

from buddy-sign.

0xqd avatar 0xqd commented on August 27, 2024

@niwinz I haven't retried it yet, work on another task. I will retry soon and report the results.

from buddy-sign.

0xqd avatar 0xqd commented on August 27, 2024

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 :)

from buddy-sign.

niwinz avatar niwinz commented on August 27, 2024

Nice to know! Thanks!

from buddy-sign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.