Class: RSA::Key
- Inherits:
-
Object
- Object
- RSA::Key
- Defined in:
- lib/rsa/key.rb
Overview
An RSA public or private key.
Refer to PKCS #1 v2.1, section 3, pp. 6-8.
Instance Attribute Summary collapse
-
#exponent ⇒ Integer
(also: #e, #d)
readonly
The RSA public or private exponent, a positive integer.
-
#modulus ⇒ Integer
(also: #n)
readonly
The RSA modulus, a positive integer.
Instance Method Summary collapse
-
#initialize(modulus, exponent, options = {}) ⇒ Key
constructor
Initializes a new key.
-
#to_a ⇒ Array
Returns a two-element array containing the modulus and exponent.
-
#valid? ⇒ Boolean
Returns ‘true` if this is a valid RSA key according to PKCS #1.
Constructor Details
#initialize(modulus, exponent, options = {}) ⇒ Key
Initializes a new key.
31 32 33 34 35 |
# File 'lib/rsa/key.rb', line 31 def initialize(modulus, exponent, = {}) @modulus = modulus.to_i @exponent = exponent.to_i = .dup end |
Instance Attribute Details
#exponent ⇒ Integer (readonly) Also known as: e, d
The RSA public or private exponent, a positive integer.
21 22 23 |
# File 'lib/rsa/key.rb', line 21 def exponent @exponent end |
#modulus ⇒ Integer (readonly) Also known as: n
The RSA modulus, a positive integer.
14 15 16 |
# File 'lib/rsa/key.rb', line 14 def modulus @modulus end |
Instance Method Details
#to_a ⇒ Array
Returns a two-element array containing the modulus and exponent.
50 51 52 |
# File 'lib/rsa/key.rb', line 50 def to_a [modulus, exponent] end |
#valid? ⇒ Boolean
Returns ‘true` if this is a valid RSA key according to PKCS #1.
42 43 44 |
# File 'lib/rsa/key.rb', line 42 def valid? true # TODO: PKCS #1 v2.1, sections 3.1 and 3.2, pp. 6-7. end |