Class: JWT::JWK::RSA
- Inherits:
-
Object
- Object
- JWT::JWK::RSA
- Defined in:
- lib/jwt/jwk/rsa.rb
Constant Summary collapse
- BINARY =
2
- KTY =
'RSA'.freeze
Instance Attribute Summary collapse
-
#keypair ⇒ Object
readonly
Returns the value of attribute keypair.
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(keypair) ⇒ RSA
constructor
A new instance of RSA.
- #kid ⇒ Object
- #private? ⇒ Boolean
- #public_key ⇒ Object
Constructor Details
#initialize(keypair) ⇒ RSA
Returns a new instance of RSA.
11 12 13 14 15 |
# File 'lib/jwt/jwk/rsa.rb', line 11 def initialize(keypair) raise ArgumentError, 'keypair must be of type OpenSSL::PKey::RSA' unless keypair.is_a?(OpenSSL::PKey::RSA) @keypair = keypair end |
Instance Attribute Details
#keypair ⇒ Object (readonly)
Returns the value of attribute keypair.
6 7 8 |
# File 'lib/jwt/jwk/rsa.rb', line 6 def keypair @keypair end |
Class Method Details
.import(jwk_data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jwt/jwk/rsa.rb', line 40 def self.import(jwk_data) imported_key = OpenSSL::PKey::RSA.new 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 |
Instance Method Details
#export ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/jwt/jwk/rsa.rb', line 31 def export { kty: KTY, n: ::Base64.urlsafe_encode64(public_key.n.to_s(BINARY), padding: false), e: ::Base64.urlsafe_encode64(public_key.e.to_s(BINARY), padding: false), kid: kid } end |
#kid ⇒ Object
25 26 27 28 29 |
# File 'lib/jwt/jwk/rsa.rb', line 25 def kid sequence = OpenSSL::ASN1::Sequence([OpenSSL::ASN1::Integer.new(public_key.n), OpenSSL::ASN1::Integer.new(public_key.e)]) OpenSSL::Digest::SHA256.hexdigest(sequence.to_der) end |
#private? ⇒ Boolean
17 18 19 |
# File 'lib/jwt/jwk/rsa.rb', line 17 def private? keypair.private? end |
#public_key ⇒ Object
21 22 23 |
# File 'lib/jwt/jwk/rsa.rb', line 21 def public_key keypair.public_key end |