gpt4 book ai didi

java - 在 Clojure/Java 中解码 JWT

转载 作者:行者123 更新时间:2023-12-01 18:03:34 24 4
gpt4 key购买 nike

我有一个 JWT 字符串。我可以将其粘贴到“解码 JWT”的任何顶级谷歌结果中,并且它可以正确解码,并且不需要我提供任何 secret 或加密声明。但我看到的所有例子,例如Buddy 或 jwtt,要求我提供他们加密时使用的任何 secret 。我怎样才能像每个网站一样简单地解码原始字符串?

最佳答案

下面的答案内容丰富且很好;这是对我有用的 Clojure 版本:

(ns decode-jwt
(:require [cheshire.core :as json])
(:import [org.apache.commons.codec.binary Base64]))

(-> returned-jwt ;; returned-jwt is your full jwt string
(clojure.string/split #"\.") ;; split into the 3 parts of a jwt, header, body, signature
second ;; get the body
Base64/decodeBase64 ;; read it into a byte array
String. ;; byte array to string
json/decode ;; make it into a sensible clojure map
)

关于java - 在 Clojure/Java 中解码 JWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com