Class: Gibberish::RSA::KeyPair

Inherits:
Object
  • Object
show all
Defined in:
lib/gibberish/rsa.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ KeyPair

Returns a new instance of KeyPair.



43
44
45
46
# File 'lib/gibberish/rsa.rb', line 43

def initialize(key)
  @key = key
  @cipher =  OpenSSL::Cipher.new('aes-256-cbc')
end

Instance Attribute Details

#passphraseObject

Returns the value of attribute passphrase.



41
42
43
# File 'lib/gibberish/rsa.rb', line 41

def passphrase
  @passphrase
end

Class Method Details

.generate(bits = 2048) ⇒ Object



37
38
39
# File 'lib/gibberish/rsa.rb', line 37

def self.generate(bits=2048)
  self.new(OpenSSL::PKey::RSA.generate(bits))
end

Instance Method Details

#private_keyObject



52
53
54
55
56
57
58
# File 'lib/gibberish/rsa.rb', line 52

def private_key
  if @passphrase
    @key.to_pem(@cipher, @passphrase)
  else
    @key.to_pem
  end
end

#public_keyObject



48
49
50
# File 'lib/gibberish/rsa.rb', line 48

def public_key
  @key.public_key
end

#to_sObject



60
61
62
# File 'lib/gibberish/rsa.rb', line 60

def to_s
  private_key
end