Class: Sandal::Enc::Alg::RSA
- Inherits:
-
Object
- Object
- Sandal::Enc::Alg::RSA
- Defined in:
- lib/sandal/enc/alg/rsa.rb
Overview
Base class for RSA key encryption algorithm.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The JWA name of the algorithm.
Instance Method Summary collapse
-
#decrypt_key(encrypted_key) ⇒ String
Decrypts the content key.
-
#encrypt_key(key) ⇒ String
Encrypts the content key.
-
#initialize(name, rsa_key, padding) ⇒ RSA
constructor
Initialises a new instance.
Constructor Details
#initialize(name, rsa_key, padding) ⇒ RSA
Initialises a new instance.
(private). If the value is a String then it will be passed to the constructor of the RSA class. This must be at least 2048 bits to be compliant with the JWA specification.
19 20 21 22 23 |
# File 'lib/sandal/enc/alg/rsa.rb', line 19 def initialize(name, rsa_key, padding) @name = name @rsa_key = rsa_key.is_a?(String) ? OpenSSL::PKey::RSA.new(rsa_key) : rsa_key @padding = padding end |
Instance Attribute Details
#name ⇒ Object (readonly)
The JWA name of the algorithm.
11 12 13 |
# File 'lib/sandal/enc/alg/rsa.rb', line 11 def name @name end |
Instance Method Details
#decrypt_key(encrypted_key) ⇒ String
Decrypts the content key.
38 39 40 41 42 |
# File 'lib/sandal/enc/alg/rsa.rb', line 38 def decrypt_key(encrypted_key) @rsa_key.private_decrypt(encrypted_key, @padding) rescue => e raise Sandal::InvalidTokenError, "Cannot decrypt content key: #{e.}" end |
#encrypt_key(key) ⇒ String
Encrypts the content key.
29 30 31 |
# File 'lib/sandal/enc/alg/rsa.rb', line 29 def encrypt_key(key) @rsa_key.public_encrypt(key, @padding) end |