Class: Plus4uCodebase::Security::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/plus4u_codebase/security/ssh_key.rb

Overview

Ssh key generated by #generate_key method.

Instance Method Summary collapse

Constructor Details

#initialize(ssh_key) ⇒ SSHKey

Returns a new instance of SSHKey



9
10
11
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 9

def initialize(ssh_key)
  @ssh_key = ssh_key
end

Instance Method Details

#bitsFixnum

Determine the strength of the key in bits as an integer.

Examples:

# generate key
key = Plus4uCodebase::Security.generate_key(comment: '13-666-1')

# get number of bits
key.bits # 2048

Returns:

  • (Fixnum)

    Returns number of bits.



66
67
68
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 66

def bits
  @ssh_key.bits
end

#private_keyString

Returns private ssh key as String.

Examples:

# generate key
key = Plus4uCodebase::Security.generate_key(comment: '13-666-1')

# get private key as string
key.private_key # String '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAxVu3AQL9M4Fk...'

Returns:

  • (String)

    Private ssh key.



37
38
39
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 37

def private_key
  @ssh_key.private_key
end

#public_keyString

Returns public ssh key as String.

Examples:

# generate key
key = Plus4uCodebase::Security.generate_key(comment: '13-666-1')

# get public key as string
key.public_key # String 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ...'

Returns:

  • (String)

    Public ssh key.



23
24
25
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 23

def public_key
  @ssh_key.ssh_public_key
end

#randomartString

Generate OpenSSH compatible ASCII art fingerprints.

Examples:

# generate key
key = Plus4uCodebase::Security.generate_key(comment: '13-666-1')

# get randomart
key.randomart # String '"+--[ RSA 2048]----+\n|                 |\n|                 |\n|         '

Returns:



51
52
53
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 51

def randomart
  @ssh_key.randomart
end

#typeString

Ssh key type. Can be RSA or DSA.

Examples:

# generate key
key = Plus4uCodebase::Security.generate_key(comment: '13-666-1')

# get ssh key type
key.type # String 'rsa'

Returns:

  • (String)

    Returns ssh key type.



80
81
82
# File 'lib/plus4u_codebase/security/ssh_key.rb', line 80

def type
  @ssh_key.type
end