Class: DiceBag::PrivateKey

Inherits:
Object
  • Object
show all
Defined in:
lib/dice_bag/private_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ PrivateKey

Returns a new instance of PrivateKey.



7
8
9
# File 'lib/dice_bag/private_key.rb', line 7

def initialize(key)
  @private_key = key
end

Instance Attribute Details

#private_keyObject

Returns the value of attribute private_key.



5
6
7
# File 'lib/dice_bag/private_key.rb', line 5

def private_key
  @private_key
end

Instance Method Details

#public_keyObject



30
31
32
# File 'lib/dice_bag/private_key.rb', line 30

def public_key
  rsa_object.public_key
end

#rsa_objectObject



34
35
36
# File 'lib/dice_bag/private_key.rb', line 34

def rsa_object
  @rsa_object ||= OpenSSL::PKey::RSA.new(@private_key)
end

#to_rsa_format!Object



23
24
25
26
27
28
# File 'lib/dice_bag/private_key.rb', line 23

def to_rsa_format!
  strip_down_key
  body = @private_key.split(/\s+/)
  body = body.first.scan(/.{1,64}/) if body.length == 1
  @private_key = [HEADER, body, FOOTER].flatten.join("\n")
end

#valid_private_key?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dice_bag/private_key.rb', line 11

def valid_private_key?
  require "openssl"

  begin
    rsa_object
    true
  rescue => e
    puts "#{e.message}\n#{e.backtrace}"
    false
  end
end