久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 android 中解碼 JWT 令牌?

How can I decode JWT token in android?(如何在 android 中解碼 JWT 令牌?)
本文介紹了如何在 android 中解碼 JWT 令牌?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問題描述

我有一個(gè)像這樣的 jwt 令牌

I have a jwt token like this

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

我怎樣才能解碼這個(gè),這樣我才能得到這樣的有效載荷

How can I decode this so that I can get the payload like this

{
  "sub": "1234567890",
  "name": "John Doe",
  "admin": true
}

我使用過 this 庫(kù),但找不到做我想做的事情的方法p>

I have used this library , but can't find a way to do what I want

推薦答案

你應(yīng)該拆分字符串:如果您通過 base 64 解碼器傳遞前兩個(gè)部分,您將得到以下內(nèi)容(為清晰起見添加了格式):

you should split string: If you pass the first two sections through a base 64 decoder, you'll get the following (formatting added for clarity):

標(biāo)題

{
  "alg": "HS256",
  "typ": "JWT"
}

身體

    {
  "sub": "1234567890",
  "name": "John Doe",
  "admin": true
}

代碼示例:

public class JWTUtils {

    public static void decoded(String JWTEncoded) throws Exception {
        try {
            String[] split = JWTEncoded.split("\.");
            Log.d("JWT_DECODED", "Header: " + getJson(split[0]));
            Log.d("JWT_DECODED", "Body: " + getJson(split[1]));
        } catch (UnsupportedEncodingException e) {
            //Error
        }
    }

    private static String getJson(String strEncoded) throws UnsupportedEncodingException{
        byte[] decodedBytes = Base64.decode(strEncoded, Base64.URL_SAFE);
        return new String(decodedBytes, "UTF-8");
    }
}

調(diào)用方法舉例

Call method for example

JWTUtils.decoded("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ");

庫(kù)參考:https://github.com/jwtk/jjwt

jwt 測(cè)試:https://jwt.io/

這篇關(guān)于如何在 android 中解碼 JWT 令牌?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲欧美国产毛片在线 | 亚洲视频第一页 | 久久久久久久久久久一区二区 | 日韩中文一区二区三区 | 久久国产精品一区二区三区 | 伊人二区 | 成人a视频片观看免费 | 国产在线一区二区三区 | 精品久久久久国产免费第一页 | 免费看a| 日本小电影在线 | 一级片免费视频 | 国产一区 日韩 | 国产精品99久久久久久人 | 亚洲手机视频在线 | 一级在线免费观看 | 久久午夜剧场 | 日韩激情网 | 黄色大片毛片 | 精品视频在线观看 | 91传媒在线观看 | 一区二区日韩精品 | 国产成人99久久亚洲综合精品 | 九九热最新视频 | 天天射网站 | xx性欧美肥妇精品久久久久久 | 久久九| 日韩中文一区 | 成人中文字幕在线观看 | 亚洲视频www| 欧美精品乱码99久久影院 | 精品一区二区三区免费视频 | 久久宗合色 | 久久久久国产一区二区三区 | 亚洲狠狠爱 | 久草99| 亚洲精品一区在线 | 九九爱这里只有精品 | 麻豆国产一区二区三区四区 | 国产成人精品在线 | 99re在线视频|