Class: RSA::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/rsa-g/key.rb

Overview

An RSA public or private key.

Refer to PKCS #1 v2.1, section 3, pp. 6-8.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modulus, exponent, options = {}) ⇒ Key

Initializes a new key.



31
32
33
34
35
# File 'lib/rsa-g/key.rb', line 31

def initialize(modulus, exponent, options = {})
  @modulus  = modulus.to_i
  @exponent = exponent.to_i
  @options  = options.dup
end

Instance Attribute Details

#exponentInteger Also known as: e, d

The RSA public or private exponent, a positive integer.



21
22
23
# File 'lib/rsa-g/key.rb', line 21

def exponent
  @exponent
end

#modulusInteger Also known as: n

The RSA modulus, a positive integer.



14
15
16
# File 'lib/rsa-g/key.rb', line 14

def modulus
  @modulus
end

Instance Method Details

#to_aArray

Returns a two-element array containing the modulus and exponent.



50
51
52
# File 'lib/rsa-g/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-g/key.rb', line 42

def valid?
  true # TODO: PKCS #1 v2.1, sections 3.1 and 3.2, pp. 6-7.
end