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.

See Also:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Key) initialize(modulus, exponent, options = {})

Initializes a new key.

Parameters:

  • (Integer, #to_i) modulus
  • (Integer, #to_i) exponent
  • (Hash{Symbol => Object}) options (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

- (Integer) exponent (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

- (Integer) modulus (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

- (Array) to_a

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

- (Boolean) valid?

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