Class: RSA::Key

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

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

Initializes a new key.

Parameters:

  • modulus (Integer, #to_i)
  • exponent (Integer, #to_i)
  • options (Hash{Symbol => Object}) (defaults to: {})


31
32
33
34
35
# File 'lib/rsa/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 (readonly) Also known as: e, d

The RSA public or private exponent, a positive integer.

Returns:

  • (Integer)


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

def exponent
  @exponent
end

#modulusInteger (readonly) Also known as: n

The RSA modulus, a positive integer.

Returns:

  • (Integer)


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

def modulus
  @modulus
end

Instance Method Details

#to_aArray

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

Returns:

  • (Array)


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.

Returns:

  • (Boolean)


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