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
# File 'lib/json/jwk/jwkizable.rb', line 5

def to_jwk(ex_params = {})
  params = {
    kty: :RSA,
    e: UrlSafeBase64.encode64(e.to_s(2)),
    n: UrlSafeBase64.encode64(n.to_s(2))
  }.merge ex_params
  if private?
    params.merge!(
      d: UrlSafeBase64.encode64(d.to_s(2)),
      p: UrlSafeBase64.encode64(p.to_s(2)),
      q: UrlSafeBase64.encode64(q.to_s(2))
    )
  end
  JWK.new params
end