使用公钥的JWT令牌验证

时间:2018-07-21 14:45:37

标签: c# jwt x509certificate2

我正在尝试使用公共密钥来验证我的JWT,但出现了如下所示的异常;你能帮我这个忙吗?

在行下方调用时出错;

[root@VM-ACTION telnet]# netstat -antpl | grep 5432
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN                                                                                   14507/postmaster
tcp        0      0 10.9.10.83:5432         10.9.10.83:40942        ESTABLISHED                                                                              16181/postgres: etp
tcp      126      0 10.9.10.83:58240        10.9.10.83:5432         CLOSE_WAIT                                                                               12980/hrmtpr
tcp      126      0 10.9.10.83:58212        10.9.10.83:5432         CLOSE_WAIT                                                                               12950/hrmtrt
tcp      126      0 10.9.10.83:58210        10.9.10.83:5432         CLOSE_WAIT                                                                               12948/hrmdisp
tcp        0      0 127.0.0.1:5432          127.0.0.1:41280         ESTABLISHED                                                                              14586/postgres: etp
tcp        0      0 10.9.10.83:5432         10.9.10.83:40936        ESTABLISHED                                                                              16178/postgres: etp
tcp      126      0 10.9.10.83:58214        10.9.10.83:5432         CLOSE_WAIT                                                                               12951/hrmtrt
tcp      126      0 10.9.10.83:58218        10.9.10.83:5432         CLOSE_WAIT                                                                               12953/hrmtrt
tcp        0      0 10.9.10.83:5432         10.9.10.83:40934        ESTABLISHED                                                                              16176/postgres: etp
tcp        0      0 10.9.10.83:40928        10.9.10.83:5432         ESTABLISHED                                                                              16140/hrmlog
tcp        0      0 10.9.10.83:40942        10.9.10.83:5432         ESTABLISHED                                                                              16180/hrmtra
tcp        0      0 10.9.10.83:40932        10.9.10.83:5432         ESTABLISHED                                                                              16173/hrmsrv
tcp        0      0 10.9.10.83:40952        10.9.10.83:5432         ESTABLISHED                                                                              16192/hrmtra
tcp        0      0 10.9.10.83:40936        10.9.10.83:5432         ESTABLISHED                                                                              16177/hrmtra
tcp        0      0 10.9.10.83:5432         10.9.10.83:40928        ESTABLISHED                                                                              16141/postgres: etp
tcp      126      0 10.9.10.83:58964        10.9.10.83:5432         CLOSE_WAIT                                                                               13017/adtacq
tcp        0      0 127.0.0.1:5432          127.0.0.1:41236         ESTABLISHED                                                                              14520/postgres: etp
tcp        0      0 10.9.10.83:5432         10.9.10.83:40932        ESTABLISHED                                                                              16174/postgres: etp
tcp        0      0 10.9.10.83:5432         10.9.10.83:40952        ESTABLISHED                                                                              16193/postgres: etp
tcp        0      0 10.9.10.83:40934        10.9.10.83:5432         ESTABLISHED                                                                              16175/hrmtra
tcp      126      0 10.9.10.83:58220        10.9.10.83:5432         CLOSE_WAIT                                                                               12954/hrmtrt
tcp        0      0 10.9.10.83:40946        10.9.10.83:5432         ESTABLISHED                                                                              16188/hrmtra
tcp      126      0 10.9.10.83:58216        10.9.10.83:5432         CLOSE_WAIT                                                                               12952/hrmtrt
tcp        0      0 10.9.10.83:5432         10.9.10.83:52714        TIME_WAIT                                                                                -
tcp      126      0 10.9.10.83:58222        10.9.10.83:5432         CLOSE_WAIT                                                                               12955/hrmtrt
tcp        0      0 10.9.10.83:5432         10.9.10.83:40946        ESTABLISHED                                                                              16189/postgres: etp
tcp6       0      0 :::5432                 :::*                    LISTEN                                                                                   14507/postmaster
tcp6       0      0 127.0.0.1:41236         127.0.0.1:5432          ESTABLISHED                                                                              2422/java
tcp6       0      0 127.0.0.1:41280         127.0.0.1:5432          ESTABLISHED                                                                              2422/java

代码段为:

var certificate = new X509Certificate2(Convert.FromBase64String(key));

1 个答案:

答案 0 :(得分:0)

我想对您来说有点晚了,但对于其他与此有关的人来说

我猜错误是:CryptographicException: Object not found

这是当您尝试仅使用公钥初始化完整的X509证书时。这是它的一部分,但是缺少许多其他内容,例如到期日期和主题。

您将必须使用以下各行指示的完整证书来初始化X509Certificate2,但是在从Base64转换它们之前将其删除,以便仅对内容进行解码:

-----BEGIN CERTIFICATE-----
(content)
-----END CERTIFICATE-----