【问题标题】:Error "Failed to decode JWT: Unsupported algorithm or incorrect key" when I'm trying to decode my token on JSONWebToken's Framework当我尝试在 JSONWebToken 的框架上解码我的令牌时出现错误“无法解码 JWT:不支持的算法或不正确的密钥”
【发布时间】:2017-10-05 16:08:52
【问题描述】:

我有以下代码:

if let user = response.result.value{
    do {
       let claims: ClaimSet = try JWT.decode(user.access_token, algorithm: .hs256(self.jwtSecret.data(using: .utf8)!))
       user.id = claims["sub"] as! Int
       user.iss = claims["iss"] as! String
       print(claims)
       } catch {
          print("Failed to decode JWT: \(error)")
          reject(error)
         }
}

但我有这个错误。现在,当我在 jwt.io 上进行验证时,我得到了有效的解码。有一张验证的图片:

所以我不明白我做错了什么。有什么建议吗?

最好的问候

【问题讨论】:

  • 您正在尝试使用 HMAC 密钥 (.hs256) 对使用 RSA (RS256) 签名的令牌进行解码。需要对应的公钥来验证token
  • mmm... 有 RSA256 算法的 pod 吗?

标签: ios swift jwt xcode9 json-web-token


【解决方案1】:

您的密钥不在 base64 中。它应该是 base64。

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2021-12-12
    • 2021-08-08
    • 2021-06-30
    • 2019-10-31
    • 2021-11-05
    • 2020-12-01
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多