Class: Ronin::Support::Crypto::Key::RSA
- Inherits:
-
OpenSSL::PKey::RSA
- Object
- OpenSSL::PKey::RSA
- Ronin::Support::Crypto::Key::RSA
- Includes:
- Methods
- Defined in:
- lib/ronin/support/crypto/key/rsa.rb
Overview
Represents an RSA key.
Constant Summary collapse
- PADDINGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of padding names to pdding constants.
{ pkcs1_oaep: PKCS1_OAEP_PADDING, pkcs1: PKCS1_PADDING, sslv23: SSLV23_PADDING, nil => NO_PADDING, false => NO_PADDING }
Class Method Summary collapse
-
.generate(key_size = 4096, *arguments, &block) ⇒ RSA
Generates a new random RSA key.
Instance Method Summary collapse
-
#d ⇒ OpenSSL::BN
The
d
variable for the RSA key. -
#e ⇒ OpenSSL::BN
The
e
variable for the RSA key. -
#n ⇒ OpenSSL::BN
The
n
variable for the RSA key. -
#private_decrypt(data, padding: :pkcs1) ⇒ String
Decrypts data using the private key.
-
#public_encrypt(data, padding: :pkcs1) ⇒ String
Encrypts data using the public key.
-
#size ⇒ Integer
The size of the RSA key in bits.
Methods included from Methods
Class Method Details
.generate(key_size = 4096, *arguments, &block) ⇒ RSA
Generates a new random RSA key.
51 52 53 54 55 56 57 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 51 def self.generate(key_size=4096,*arguments,&block) # HACK: openssl-3.0.0 will return an OpenSSL::PKey::RSA instance, # even though we subclassed OpenSSL::PKey::RSA. new_key = allocate new_key.send(:initialize_copy,super(key_size,*arguments,&block)) new_key end |
Instance Method Details
#d ⇒ OpenSSL::BN
The d
variable for the RSA key.
88 89 90 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 88 def d super() end |
#e ⇒ OpenSSL::BN
The e
variable for the RSA key.
77 78 79 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 77 def e super() end |
#n ⇒ OpenSSL::BN
The n
variable for the RSA key.
66 67 68 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 66 def n super() end |
#private_decrypt(data, padding: :pkcs1) ⇒ String
Decrypts data using the private key.
157 158 159 160 161 162 163 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 157 def private_decrypt(data, padding: :pkcs1) padding_const = PADDINGS.fetch(padding) do raise(ArgumentError,"padding must be #{PADDINGS.keys.map(&:inspect).join(', ')}: #{padding.inspect}") end super(data,padding_const) end |
#public_encrypt(data, padding: :pkcs1) ⇒ String
Encrypts data using the public key.
131 132 133 134 135 136 137 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 131 def public_encrypt(data, padding: :pkcs1) padding_const = PADDINGS.fetch(padding) do raise(ArgumentError,"padding must be #{PADDINGS.keys.map(&:inspect).join(', ')}: #{padding.inspect}") end super(data,padding_const) end |
#size ⇒ Integer
The size of the RSA key in bits.
98 99 100 |
# File 'lib/ronin/support/crypto/key/rsa.rb', line 98 def size n.num_bits end |