Skip to content

Instantly share code, notes, and snippets.

@wout
Last active August 6, 2020 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wout/af0e3914fa9cd687838a0f33f68ef958 to your computer and use it in GitHub Desktop.
Save wout/af0e3914fa9cd687838a0f33f68ef958 to your computer and use it in GitHub Desktop.
require 'jose'
require 'faraday'
require 'fast_jsonparser'
endpoint = 'https://ext.payconiq.com/certificates'
kid = 'es.signature.ext.payconiq.com'
response = Faraday.get(endpoint, {}, { 'Accept' => 'application/json' })
keys = FastJsonparser.parse(response.body).dig(:keys)
cert = keys.filter { |c| c[:kid] == kid }.first
pem = JOSE::JWK.from(cert.to_json).to_pem
puts pem
# => Output:
# -----BEGIN PUBLIC KEY-----
# MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+f5wRbYRr7I6mDs7RPIjQjdTl4ar
# HZfGHSegiqLq2HOLPOzdMMIi+dyR/jfC8L4wfAW8T32Dd5zgwSw68vr2MA==
# -----END PUBLIC KEY-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment