Skip to content

Commit

Permalink
Merge pull request #333 from rahulbajaj0509/import-ruby-issue
Browse files Browse the repository at this point in the history
Support RSA.import for all Ruby versions.
  • Loading branch information
excpt committed Sep 18, 2019
2 parents a269358 + a9c0aa8 commit f4c7f15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/jwt/jwk/rsa.rb
Expand Up @@ -39,9 +39,14 @@ def export

def self.import(jwk_data)
imported_key = OpenSSL::PKey::RSA.new
imported_key.set_key(OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:n]), BINARY),
OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:e]), BINARY),
nil)
if imported_key.respond_to?(:set_key)
imported_key.set_key(OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:n]), BINARY),
OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:e]), BINARY),
nil)
else
imported_key.n = OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:n]), BINARY)
imported_key.e = OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:e]), BINARY)
end
self.new(imported_key)
end
end
Expand Down

0 comments on commit f4c7f15

Please sign in to comment.