作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从服务器获得了以下 jwks
"keys": [
{
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"alg": "RS256",
"kid": "92595710205972640",
"n": "l75bY3woSGVAYYDR6qE0tbzxqpYLr1-zz_ShSiFOOpa-taJenFWipHm7AR2GyG36bJeHgAo8OtqcTprWwHi3NjhxQZ0bj-hyr02ZxufvGnOIJzQgPsKym9jlWIXZSZ4apJI06RbaJ95Z9ekQ-36IR8NZ5VuV3aQZd753FDVjMciyqin6ofNSE5kq-fkWf4hbyEqgKFz4SeqjFhThhUaMrzs_uyNAZnaIzyAgxRmtMxJ5Mci8L7aX9DLhAMiUAOvSGGyRI1r9KlRxEcqNlFCdYi8G74ehPorwTY6-sW3ZG6U_sA5Ns9GUmuLIkSIbueqWv_tGxYcx4ntAO6zRQocinw"
}
]
}
最佳答案
How to get the public key from the above jwk.
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/
我是一名优秀的程序员,十分优秀!