Module: JWT::Algos::Rsa
- Defined in:
- lib/jwt/algos/rsa.rb
Constant Summary collapse
- SUPPORTED =
%w[RS256 RS384 RS512].freeze
Class Method Summary collapse
- .sign(algorithm, msg, key) ⇒ Object
- .verify(algorithm, public_key, signing_input, signature) ⇒ Object
Class Method Details
.sign(algorithm, msg, key) ⇒ Object
10 11 12 13 14 |
# File 'lib/jwt/algos/rsa.rb', line 10 def sign(algorithm, msg, key) raise EncodeError, "The given key is a #{key.class}. It has to be an OpenSSL::PKey::RSA instance." if key.instance_of?(String) key.sign(OpenSSL::Digest.new(algorithm.sub('RS', 'sha')), msg) end |
.verify(algorithm, public_key, signing_input, signature) ⇒ Object
16 17 18 19 20 |
# File 'lib/jwt/algos/rsa.rb', line 16 def verify(algorithm, public_key, signing_input, signature) public_key.verify(OpenSSL::Digest.new(algorithm.sub('RS', 'sha')), signature, signing_input) rescue OpenSSL::PKey::PKeyError raise JWT::VerificationError, 'Signature verification raised' end |