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)
-
- (Integer) exponent
(also: #e, #d)
readonly
The RSA public or private exponent, a positive integer.
-
- (Integer) modulus
(also: #n)
readonly
The RSA modulus, a positive integer.
Instance Method Summary (collapse)
-
- (Key) initialize(modulus, exponent, options = {})
constructor
Initializes a new key.
-
- (Array) to_a
Returns a two-element array containing the modulus and exponent.
-
- (Boolean) valid?
Returns
trueif this is a valid RSA key according to PKCS #1.
Constructor Details
- (Key) initialize(modulus, exponent, options = {})
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 @options = .dup end |
Instance Attribute Details
- (Integer) exponent (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 |
- (Integer) modulus (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
- (Array) to_a
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 |
- (Boolean) valid?
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 |