gpt4 book ai didi

ruby-on-rails - Rails - 如何从 JSON Web key 获取公钥?

转载 作者:行者123 更新时间:2023-12-04 01:31:15 25 4
gpt4 key购买 nike

我从服务器获得了以下 jwks

    "keys": [
{
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"alg": "RS256",
"kid": "92595710205972640",
"n": "l75bY3woSGVAYYDR6qE0tbzxqpYLr1-zz_ShSiFOOpa-taJenFWipHm7AR2GyG36bJeHgAo8OtqcTprWwHi3NjhxQZ0bj-hyr02ZxufvGnOIJzQgPsKym9jlWIXZSZ4apJI06RbaJ95Z9ekQ-36IR8NZ5VuV3aQZd753FDVjMciyqin6ofNSE5kq-fkWf4hbyEqgKFz4SeqjFhThhUaMrzs_uyNAZnaIzyAgxRmtMxJ5Mci8L7aX9DLhAMiUAOvSGGyRI1r9KlRxEcqNlFCdYi8G74ehPorwTY6-sW3ZG6U_sA5Ns9GUmuLIkSIbueqWv_tGxYcx4ntAO6zRQocinw"
}
]
}

我有一个编码的 token 。我想用上面的jwk解密。如何从上面的jwk中获取公钥。我遵循了 https://auth0.com/docs/quickstart/backend/rails/01-authorization 中的步骤.但是上面的 jwk 中缺少 x5c(证书)。

我想知道如何在 jwk 中没有 x5c 的情况下获取公钥。

最佳答案

How to get the public key from the above jwk.


我可以从 jwt lib 获取公钥。
irb(main):001:0> require 'jwt'
=> true
irb(main):002:0> jwk = {
irb(main):003:1* "kty": "RSA",
irb(main):004:1* "e": "AQAB",
irb(main):005:1* "use": "sig",
irb(main):006:1* "alg": "RS256",
irb(main):007:1* "kid": "92595710205972640",
irb(main):008:1* "n": "l75bY3woSGVAYYDR6qE0tbzxqpYLr1-zz_ShSiFOOpa-taJenFWipHm7AR2GyG36bJeHgAo8OtqcTprWwHi3NjhxQZ0bj-hyr02ZxufvGnOIJzQgPsKym9jlWIXZSZ4apJI06RbaJ95Z9ekQ-36IR8NZ5VuV3aQZd753FDVjMciyqin6ofNSE5kq-fkWf4hbyEqgKFz4SeqjFhThhUaMrzs_uyNAZnaIzyAgxRmtMxJ5Mci8L7aX9DLhAMiUAOvSGGyRI1r9KlRxEcqNlFCdYi8G74ehPorwTY6-sW3ZG6U_sA5Ns9GUmuLIkSIbueqWv_tGxYcx4ntAO6zRQocinw"
irb(main):009:1> }
irb(main):010:0>
irb(main):011:0> public_key = JWT::JWK::RSA.import(jwk).public_key
=> #<OpenSSL::PKey::RSA:0x00007f970287b810>
irb(main):012:0>
irb(main):013:0> puts public_key.to_pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl75bY3woSGVAYYDR6qE0
tbzxqpYLr1+zz/ShSiFOOpa+taJenFWipHm7AR2GyG36bJeHgAo8OtqcTprWwHi3
NjhxQZ0bj+hyr02ZxufvGnOIJzQgPsKym9jlWIXZSZ4apJI06RbaJ95Z9ekQ+36I
R8NZ5VuV3aQZd753FDVjMciyqin6ofNSE5kq+fkWf4hbyEqgKFz4SeqjFhThhUaM
rzs/uyNAZnaIzyAgxRmtMxJ5Mci8L7aX9DLhAMiUAOvSGGyRI1r9KlRxEcqNlFCd
Yi8G74ehPorwTY6+sW3ZG6U/sA5Ns9GUmuLIkSIbueqWv/tGxYcx4ntAO6zRQoci
nwIDAQAB
-----END PUBLIC KEY-----

关于ruby-on-rails - Rails - 如何从 JSON Web key 获取公钥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60988699/

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