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.



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

def initialize(key)
  @private_key = key
end

Instance Attribute Details

#private_keyObject

Returns the value of attribute private_key.



3
4
5
# File 'lib/dice_bag/private_key.rb', line 3

def private_key
  @private_key
end

Instance Method Details

#to_rsa_format!Object



21
22
23
24
25
26
# File 'lib/dice_bag/private_key.rb', line 21

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)


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

def valid_private_key?
  require "openssl"

  begin
    OpenSSL::PKey::RSA.new @private_key
    true
  rescue => e
    puts "#{e.message}\n#{e.backtrace}"
    false
  end
end