Class: SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkey.rb,
lib/sshkey/version.rb

Constant Summary collapse

VERSION =
"1.1.2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key, options = {}) ⇒ SSHKey

Returns a new instance of SSHKey.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sshkey.rb', line 13

def initialize(private_key, options = {})
  @key_object        = OpenSSL::PKey::RSA.new(private_key)
  @comment           = options[:comment] || ""
  @rsa_private_key   = @key_object.to_pem
  @rsa_public_key    = @key_object.public_key.to_pem
  raw_ssh_public_key = ssh_public_key_conversion
  @ssh_public_key    = [
    "ssh-rsa",
    Base64.encode64(raw_ssh_public_key).gsub("\n", ""),
    @comment,
  ].join(" ").strip
  @fingerprint       = Digest::MD5.hexdigest(raw_ssh_public_key).gsub(/(.{2})(?=.)/, '\1:\2')
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



11
12
13
# File 'lib/sshkey.rb', line 11

def comment
  @comment
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



11
12
13
# File 'lib/sshkey.rb', line 11

def fingerprint
  @fingerprint
end

#key_objectObject (readonly)

Returns the value of attribute key_object.



11
12
13
# File 'lib/sshkey.rb', line 11

def key_object
  @key_object
end

#rsa_private_keyObject (readonly)

Returns the value of attribute rsa_private_key.



11
12
13
# File 'lib/sshkey.rb', line 11

def rsa_private_key
  @rsa_private_key
end

#rsa_public_keyObject (readonly)

Returns the value of attribute rsa_public_key.



11
12
13
# File 'lib/sshkey.rb', line 11

def rsa_public_key
  @rsa_public_key
end

#ssh_public_keyObject (readonly)

Returns the value of attribute ssh_public_key.



11
12
13
# File 'lib/sshkey.rb', line 11

def ssh_public_key
  @ssh_public_key
end

Class Method Details

.generate(options = {}) ⇒ Object



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

def self.generate(options = {})
  SSHKey.new(OpenSSL::PKey::RSA.generate(2048).to_pem, options)
end