Class: JWT::JWK::RSA
- Inherits:
-
Object
- Object
- JWT::JWK::RSA
- Extended by:
- Forwardable
- 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
Constructor Details
#initialize(keypair) ⇒ RSA
Returns a new instance of RSA.
15 16 17 18 19 |
# File 'lib/jwt/jwk/rsa.rb', line 15 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.
8 9 10 |
# File 'lib/jwt/jwk/rsa.rb', line 8 def keypair @keypair end |
Class Method Details
.import(jwk_data) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/jwt/jwk/rsa.rb', line 36 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) self.new(imported_key) end |
Instance Method Details
#export ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/jwt/jwk/rsa.rb', line 27 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
21 22 23 24 25 |
# File 'lib/jwt/jwk/rsa.rb', line 21 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 |