Module: JSON::JWK::JWKizable::RSA

Defined in:
lib/json/jwk/jwkizable.rb

Instance Method Summary collapse

Instance Method Details

#to_jwk(ex_params = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/json/jwk/jwkizable.rb', line 5

def to_jwk(ex_params = {})
  params = {
    kty: :RSA,
    e: Base64.urlsafe_encode64(e.to_s(2), padding: false),
    n: Base64.urlsafe_encode64(n.to_s(2), padding: false)
  }.merge ex_params
  if private?
    params.merge!(
      d: Base64.urlsafe_encode64(d.to_s(2), padding: false),
      p: Base64.urlsafe_encode64(p.to_s(2), padding: false),
      q: Base64.urlsafe_encode64(q.to_s(2), padding: false),
      dp: Base64.urlsafe_encode64(dmp1.to_s(2), padding: false),
      dq: Base64.urlsafe_encode64(dmq1.to_s(2), padding: false),
      qi: Base64.urlsafe_encode64(iqmp.to_s(2), padding: false),
    )
  end
  JWK.new params
end